What are the 5 Basic SQL Commands? (DDL, DML, DCL, TCL, DQL)

Estimated study time: 23 minutes. Every SQL command falls into one of these five categories.

Every command you write in SQL belongs to one of five categories, based on what it actually does to the database. Knowing these categories makes it much easier to understand why SQL is organized the way it is.

1. DDL — Data Definition Language

Defines or changes the structure of database objects like tables and schemas.

CREATE TABLE students (id INT, name VARCHAR(50));
ALTER TABLE students ADD email VARCHAR(100);
DROP TABLE students;

2. DML — Data Manipulation Language

Used to insert, update, or delete the actual data stored inside tables.

INSERT INTO students VALUES (1, 'Aman');
UPDATE students SET name = 'Aman Gupta' WHERE id = 1;
DELETE FROM students WHERE id = 1;

3. DCL — Data Control Language

Controls access and permissions on database objects.

GRANT SELECT ON students TO analyst_user;
REVOKE SELECT ON students FROM analyst_user;

4. TCL — Transaction Control Language

Manages transactions, ensuring multiple statements succeed or fail together.

BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE id = 1;
COMMIT;

5. DQL — Data Query Language

Retrieves data without changing it — this is simply the SELECT statement.

SELECT name, email FROM students WHERE id = 1;
💡 Tip: Some textbooks group DQL under DML, but treating it as its own category makes it clearer that SELECT never modifies data.

Why This Grouping Matters

Recognizing which category a command belongs to helps you reason about permissions, rollback behavior, and impact — a DDL statement like DROP TABLE auto-commits in most databases, while DML changes can usually be rolled back until committed.

Placing Every Common Command in Its Group

Beginners usually remember the headline commands but get stuck on the less obvious ones. The table below sorts the commands you will meet most often in MySQL.

CategoryCommandsChanges
DDLCREATE, ALTER, DROP, TRUNCATE, RENAMEStructure of tables, views, indexes, databases
DMLINSERT, UPDATE, DELETE, REPLACERows inside existing tables
DCLGRANT, REVOKEWho is allowed to do what
TCLSTART TRANSACTION, COMMIT, ROLLBACK, SAVEPOINTWhen a group of changes becomes permanent
DQLSELECTNothing, it only reads

TRUNCATE surprises many learners. It empties a table like DELETE without a WHERE clause, yet it is classed as DDL because MySQL effectively drops and recreates the table behind the scenes.

DELETE vs TRUNCATE vs DROP

All three remove data, which is why they are a favourite interview question. The difference lies in what survives afterwards.

  • DELETE removes the rows you choose, can use a WHERE clause, fires delete triggers, and can be rolled back inside a transaction.
  • TRUNCATE removes every row, resets the AUTO_INCREMENT counter, skips row-by-row logging, and causes an implicit commit in MySQL, so you cannot undo it with ROLLBACK.
  • DROP removes the table itself, including its columns, indexes and grants on it. Any query that referenced it will fail.

Rule of thumb: use DELETE when you need control, TRUNCATE when you want a clean empty table fast, and DROP only when the table should stop existing.

A Transaction With a Savepoint, Step by Step

TCL becomes clearer once you see a partial undo. The script below records an order, then backs out only the second change.

START TRANSACTION;

INSERT INTO orders (id, customer_id, amount) VALUES (501, 7, 1200);
SAVEPOINT after_order;

UPDATE customers SET loyalty_points = loyalty_points + 120 WHERE id = 7;

-- Points rule turned out to be wrong, undo just the UPDATE
ROLLBACK TO SAVEPOINT after_order;

COMMIT;   -- the order row is saved, the points change is not

And here is DCL in MySQL form, where a user account includes the host it connects from:

CREATE USER 'report_user'@'localhost' IDENTIFIED BY 'Str0ng!Pass';
GRANT SELECT ON school.students TO 'report_user'@'localhost';
SHOW GRANTS FOR 'report_user'@'localhost';
REVOKE SELECT ON school.students FROM 'report_user'@'localhost';

Traps When Categories Meet

  • DDL inside a transaction. In MySQL, running ALTER or CREATE in the middle of a transaction commits the work done so far. A later ROLLBACK will not bring it back.
  • Autocommit is on by default. Each DML statement commits immediately unless you start a transaction first. Many people discover this after an UPDATE without a WHERE clause.
  • Table engine matters. TCL only protects tables that support transactions, such as InnoDB. Changes to a MyISAM table cannot be rolled back.
  • Granting too much. Giving ALL PRIVILEGES ON *.* to an application account is a shortcut that turns a small bug into a data loss incident.

Before running any risky statement, ask two questions: which category is this, and can I undo it? If the answer to the second is no, take a backup or test on a copy first.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with Uncodemy's Data Analytics Course.

Explore Data Analytics Course →