In SQL, DDL stands for Data Definition Language. DDL is used to define, modify, and manage the structure of database objects such as tables, indexes, and schemas. Unlike DML (Data Manipulation Language), DDL focuses on the structure of the data rather than the data itself.
Here are the main DDL commands in SQL:
- CREATE
Used to create a new database object like a table, index, or view.CREATE TABLE Employees ( EmployeeID INT PRIMARY KEY, Name VARCHAR(50), Department VARCHAR(50), Salary DECIMAL(10, 2) );
- ALTER
Used to modify an existing database object (e.g., add or drop a column, change datatype).ALTER TABLE Employees ADD DateOfJoining DATE;
- DROP
Used to delete a database object permanently.DROP TABLE Employees;
- TRUNCATE
Removes all rows from a table but keeps the table structure intact. It is faster thanDELETE
because it doesn’t log individual row deletions.TRUNCATE TABLE Employees;
- RENAME (in some SQL dialects)
Used to rename a database object.ALTER TABLE Employees RENAME TO Staff;
✅ Key points about DDL:
- Changes made by DDL commands are auto-committed in most databases, meaning you cannot roll them back (unlike DML).
- DDL affects schema objects, not the data directly.