SQL Commands – DDL, DML, DQL, DCL, TCL
In this lesson: Types of SQL commands — DDL, DML, DQL, DCL, TCL — full list with examples and comparison table for exams.
SQL commands in groups
SQL has many commands, but they fall into five clear categories based on what they do. Learning these groups — DDL, DML, DQL, DCL, TCL — makes the whole language easier to understand, because each command's job becomes obvious from its group.
DDL — Data Definition Language
DDL commands define or change the structure of the database (tables, columns).
CREATE TABLE students (roll INT, name VARCHAR(50)); ALTER TABLE students ADD marks INT; DROP TABLE students;
Main DDL commands: CREATE, ALTER, DROP, TRUNCATE. They shape the "containers" that hold data.
DML — Data Manipulation Language
DML commands change the data inside tables.
INSERT INTO students VALUES (1, 'Aman', 88); UPDATE students SET marks = 90 WHERE roll = 1; DELETE FROM students WHERE roll = 1;
Main DML commands: INSERT, UPDATE, DELETE. They add, modify and remove rows.
DQL — Data Query Language
DQL is about reading data. It has one main command:
SELECT name, marks FROM students WHERE marks > 40;
SELECT fetches data without changing anything, so it is safe to run any time. This is the command you will use most.
DCL — Data Control Language
DCL manages permissions — who can do what.
GRANT SELECT ON school.* TO 'user'@'localhost'; REVOKE INSERT ON school.* FROM 'user'@'localhost';
Main DCL commands: GRANT (give permission) and REVOKE (take it away). Used by administrators for security.
TCL — Transaction Control Language
TCL manages transactions — groups of changes that must all succeed or all fail.
START TRANSACTION; UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT; -- or ROLLBACK to undo
Main TCL commands: COMMIT, ROLLBACK, SAVEPOINT. They keep related changes consistent, like a money transfer.
Summary table
| Category | Purpose | Commands |
|---|---|---|
| DDL | Define structure | CREATE, ALTER, DROP, TRUNCATE |
| DML | Change data | INSERT, UPDATE, DELETE |
| DQL | Read data | SELECT |
| DCL | Permissions | GRANT, REVOKE |
| TCL | Transactions | COMMIT, ROLLBACK, SAVEPOINT |
Common mistakes
- Confusing DDL and DML. DDL changes structure; DML changes data.
- Thinking TRUNCATE is DML. It removes all rows but is DDL, and cannot be rolled back easily.
- Forgetting COMMIT. In a transaction, changes are not final until you COMMIT.
- Running DDL/DML carelessly in production. These change things; SELECT is the safe read-only one.
Summary
- SQL commands fall into DDL, DML, DQL, DCL and TCL.
- DDL defines structure (CREATE, ALTER, DROP).
- DML changes data (INSERT, UPDATE, DELETE).
- DQL reads data (SELECT); DCL controls permissions.
- TCL manages transactions (COMMIT, ROLLBACK).
Next, use DDL in first commands, or compare removal commands in DROP vs TRUNCATE vs DELETE.
