Data Definition Language (DDL) statements are used to define the database structure or schema. DDL statements are used to build and modify the structure of your tables and other objects in the database. When you execute a DDL statement, it takes effect immediately.
- CREATE: To create objects in the database
- ALTER: Alters the structure of the database
- DROP: Delete objects from the database
- TRUNCATE: Remove all records from a table, including all spaces allocated for the records are removed
- COMMENT: Comments added to the data dictionary.
- RENAME: Rename an object of the Database.
CREATE TABLE < table_name> ( <attribute_name 1> <data_type 1>, <attribute_name n> <data_type n>);
ALTER TABLE <table_name>ADD CONSTRAINT <constraint_name> PRIMARY KEY (<attribute_list>);
The foreign key constraint is a bit more complicated, since we have to specify both the Foreign Key attributes in this (child) table, and the Primary Key attributes that they link to in the parent table.
ALTER TABLE <table_name>ADD CONSTRAINT <constraint_name> FOREIGN KEY (<attribute_list>)REFERENCES <parent_table_name> (<attribute_list>);
DROP TABLE <table_name>ALTER TABLE <table_name> DROP CONSTRAINT <constraint name>;