DDL statements define and reshape the structure of your database: tables, columns, and constraints. This is the first of the four SQL families covered in its own lesson.
Creates a new table with a defined set of columns and data types.
CREATE TABLE table_name (
column datatype constraints
);CREATE TABLE Employee (
id INT PRIMARY KEY,
name VARCHAR(100),
department VARCHAR(50),
salary DECIMAL(10,2)
);Common Mistake
Forgetting a PRIMARY KEY, which makes rows impossible to uniquely reference.
Removes a table permanently — structure and data both.
DROP TABLE table_name;DROP TABLE Employee;Common Mistake
Running DROP TABLE when TRUNCATE (keep structure, clear rows) was actually intended.
Deletes every row from a table but keeps the table itself.
TRUNCATE TABLE table_name;TRUNCATE TABLE Employee;Common Mistake
Using TRUNCATE expecting a WHERE clause to work — it always clears the whole table.
Modifies the structure of an existing table.
ALTER TABLE table_name ADD | DROP COLUMN | ALTER COLUMN ...;-- Add a column
ALTER TABLE Employee ADD email VARCHAR(100);
-- Remove a column
ALTER TABLE Employee DROP COLUMN email;
-- Change a data type
ALTER TABLE Employee ALTER COLUMN salary DECIMAL(12,2);Common Mistake
Narrowing a column's type (e.g. VARCHAR(100) → VARCHAR(10)) and silently truncating data.
| Command | What it does |
|---|---|
| CREATE TABLE | Builds a new table with typed columns |
| DROP TABLE | Removes a table permanently — structure and data |
| TRUNCATE TABLE | Clears every row, keeps the table structure |
| ALTER TABLE | Adds, removes, or changes columns on an existing table |
DDL shapes the structure. The next lesson covers DML — the commands you'll actually type the most, for reading and changing the data inside that structure.