SQL DDL Data Definition Language
CREATE TABLE 〈table_name〉(
〈column_name〉 〈data_type〉,
〈column_name〉 〈data_type〉,
...
PRIMARY KEY (〈column_name〉, 〈column_name〉, ...) );
SEE ALSO:
CREATE TABLE 〈table name〉 AS
〈query〉;
#Example
%%sql
DROP TABLE IF EXISTS patient;
CREATE TABLE patient (
patient_id CHAR(4),
patient_name VARCHAR(20),
date_of_birth DATE,
gender CHAR(6),
height_cm DECIMAL(4,1),
weight_kg DECIMAL(4,1),
doctor_id CHAR(4),
PRIMARY KEY (patient_id)
);
DROP TABLE someTable;
DROP TABLE IF EXISTS someTable;
ALTER TABLE
ADD CONSTRAINT
ALTER TABLE 〈table name〉
ADD CONSTRAINT 〈constraint name〉
〈constraint definition〉;
ALTER TABLE DROP CONSTRAINT
ALTER TABLE 〈table name〉
DROP CONSTRAINT 〈constraint name〉;
ALTER TABLE ADD CONSTRAINT UNIQUE
ALTER TABLE 〈table name〉
ADD CONSTRAINT 〈constraint name〉
UNIQUE (〈column 1〉, 〈column 2〉, ..., 〈column n〉);
ALTER TABLE ADD CONSTRAINT CHECK
ALTER TABLE 〈table name〉
ADD CONSTRAINT 〈constraint name〉
CHECK 〈condition〉;
ALTER TABLE ADD CONSTRAINT primarykey
ALTER TABLE tableName ADD CONSTRAINT name_pk PRIMARY KEY (column);
ALTER TABLE ADD CONSTRAINT foreignkey
ALTER TABLE tableName ADD CONSTRAINT name_fk
FOREIGN KEY (column) REFERENCES childTable;
Note: FK of tableName will reference PK of childTable
No comments:
Post a Comment
Note: only a member of this blog may post a comment.