The Data Definition Language( DDL ) commands are used for creating new or modify existing schema of a relation. You can also set constraints such as key constraints, foreign key constraints, etc on a relation.
CREATE TABLE Command
This command creates a new relation or table. You must specify the fields and data type for each field while using this command.
![Figure 1: Create Table MANAGER Figure 1: Create Table MANAGER](https://notesformsc.org/wp-content/uploads/2016/01/CRATE_TABLE.png)
ALTER TABLE Command
This is most important of DDL commands because it allows us to modify the table anytime.
Here are some examples of ALTER TABLE command
Adding a primary key for the table. A primary key uniquely identifies a tuple in a relation.
![Figure 2 - Alter Table MANAGER](https://notesformsc.org/wp-content/uploads/2016/01/ALTER_TABLE.jpg.orig)
Adding a foreign key for the table. A foreign key in a relation refer to primary key of another relation and cannot be null called the Referential Integrity.
![Figure 3: Alter Table MANAGER for Foreign Key - Error](https://notesformsc.org/wp-content/uploads/2016/01/FOREIGN_KEY_ALTER.jpg.orig)
In the above example, we receive an error because the attribute ‘DEPTNO’ is not set as primary key in relation to ‘EX_DEPT’.
After adding ‘DEPTNO’ as primary key we are able to set the foreign key for ‘MANAGER’ relation.
![Figure 4: Alter Table MANAGER for Foreign Key - Success](https://notesformsc.org/wp-content/uploads/2016/01/FOREIGN_KEY_ALTER2.jpg)
Adding a new column in a Table. In the following example, we are adding ‘PCODE‘ in the ‘MANAGER’ table.
![Figure 5: Alter Table MANAGER for new column](https://notesformsc.org/wp-content/uploads/2016/01/ADDING_COL_ALTER-1.jpg)
Removing a column from a relation or table. In the following example, we are removing the ‘PCODE’ column from the ‘MANAGER’ table.
![Figure 6: Removing a Column from the Table MANAGER](https://notesformsc.org/wp-content/uploads/2016/01/DELETE_COL_ALTER.jpg)
DESC <Table Name>
The ‘DESC’ command helps view the schema of the relation.
![Figure 7: DESC <table_name> display the table schema](https://notesformsc.org/wp-content/uploads/2016/01/DESC_TABLE.jpg)
DROP TABLE <table name>
This command will drop the table permanently.
![](https://notesformsc.org/wp-content/uploads/2016/01/DROP_TABLE.jpg)
References
Avi Silberschatz, Henry F. Korth, and S. Sudarshan. 27-Jan-2010. Database System Concepts. McGraw-Hill Education.
Ramakrishnan, Johannes Gehrke, and Raghu. 1996. Database Management Systems. McGraw Hill Education; Third edition (1 July 2014).
Wikipedia. n.d. Data definition language. Accessed March 14, 2018. https://en.wikipedia.org/wiki/Data_definition_language.