What is DDL?
Understand the families of SQL commands and how DDL (CREATE, ALTER, DROP) builds and changes the structure of a database.
Before you can store a single IPL score, the database needs somewhere to put it — a table with named columns, each with the right type of data. Building and reshaping those containers is the job of DDL. In the previous chapters you only read data with SELECT. In this chapter you become the architect: you design the tables yourself.
Definition
DDL (Data Definition Language) is the group of SQL commands that create, change and remove the structure (schema) of database objects — such as tables, columns and constraints — without working on the individual rows of data stored inside them.
Let's unpack that:
- Structure / schema means the shape of a table: its name, its columns, each column's data type, and the rules (constraints) attached to it. Think of it as the blueprint of a stadium, not the spectators sitting in it.
- Database objects are the things that live in a database: tables mostly, but also views, indexes, schemas and more.
- Not the rows — DDL does not add, edit or delete individual players. That is DML's job (next chapter).
The families of SQL commands
The course groups SQL commands into three main families:
| Family | Full form | What it works on | Commands |
|---|---|---|---|
| DQL | Data Query Language | Reads data | SELECT |
| DDL | Data Definition Language | The structure of tables | CREATE, ALTER, DROP |
| DML | Data Manipulation Language | The data (rows) inside tables | INSERT, UPDATE, DELETE |
Note: You will also hear about two more families: DCL (Data Control Language —
GRANT,REVOKEfor permissions) and TCL (Transaction Control Language —COMMIT,ROLLBACK). They are not part of this chapter, but interviewers love asking for the full list.
The three DDL commands
| Command | What it does | Cricket analogy |
|---|---|---|
CREATE | Builds a new object (e.g. a brand-new, empty table) | Building a new stadium |
ALTER | Changes the structure of an existing object (add/drop/change a column) | Adding a new stand to the stadium |
DROP | Deletes the object completely — structure and all its data | Demolishing the stadium |
Structure vs data — the key idea
Look at the players table:
| id | name | team | country | runs |
|---|---|---|---|---|
| 1 | Virat Kohli | RCB | India | 750 |
| 2 | Rohit Sharma | MI | India | 500 |
- The header row — the column names
id, name, team, country, runsand their data types — is the structure. DDL works here. - The rows below the header — Virat Kohli, Rohit Sharma … — are the data. DML works there.
So "add a jersey_no column" is a DDL task (the structure changes), while "change Dhoni's runs to 400" is a DML task (only a value changes).
Example — DDL in action
sql
CREATE TABLE matches (
match_id INT NOT NULL,
home_team VARCHAR(10) NOT NULL,
away_team VARCHAR(10) NOT NULL,
CONSTRAINT pk_matches PRIMARY KEY (match_id)
);This statement does not return any rows. It simply creates an empty table called matches. In SQL Server Management Studio (SSMS) you would just see the message "Commands completed successfully."
| match_id | home_team | away_team |
|---|---|---|
| (0 rows — empty table) |
Important facts about DDL
- DDL is usually permanent. A
DROP TABLEcannot be "undone" with Ctrl+Z. (SQL Server does let you roll back DDL inside an explicit transaction, but most databases — like MySQL — auto-commit DDL immediately.) - DDL changes the database catalog — the system's list of what tables and columns exist. That is why tools like SSMS need a refresh of the Object Explorer to show your new table.
- You need permissions. In real companies, ordinary analysts often have permission to run
SELECTbut notCREATE/DROP.
Common mistakes
- ❌ Thinking
DELETEandDROPare the same. ✅DELETE(DML) removes rows;DROP(DDL) removes the whole table. - ❌ Calling
INSERTa DDL command. ✅INSERTadds data → it is DML. - ❌ Expecting
CREATE TABLEto show a result grid. ✅ DDL statements return a message, not rows.
Interview tip
Q: What is the difference between DDL and DML?
A: DDL (CREATE, ALTER, DROP) defines or changes the structure of database objects such as tables and columns. DML (INSERT, UPDATE, DELETE) adds, changes or removes the rows of data inside those tables. In short: DDL builds the container, DML fills it.
Key points to remember
- SQL commands are grouped into families: DQL (SELECT), DDL (CREATE, ALTER, DROP) and DML (INSERT, UPDATE, DELETE).
- DDL = Data Definition Language: it creates, changes and removes the STRUCTURE of database objects, not individual rows.
- CREATE builds a new object, ALTER changes an existing object's structure, DROP deletes the object completely.
- The column names and data types are the structure (DDL); the rows below them are the data (DML).
- DDL statements return a success message, not a result grid.
- DDL is usually permanent — a dropped table and its data are gone.
- DCL (GRANT/REVOKE) and TCL (COMMIT/ROLLBACK) are two more command families worth knowing for interviews.
Try it yourself
Create a table, then look inside it
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
All three families in one script
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: build your own table
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
