Final lesson — and it's the one that organises everything you already know. Every SQL command you've met belongs to one of four families, sorted by what it acts on: the building (DDL), the contents (DML), the keys to the building (DCL), or the safety rules for moving contents (TCL). Interviewers open with this classification constantly — and hiding inside it is the single most-asked SQL comparison of all time: DELETE vs TRUNCATE vs DROP.
The four families at a glance
| Family | Acts on | Commands |
|---|---|---|
| DDL — Data Definition | structure (tables, indexes, views) | CREATE, ALTER, DROP, TRUNCATE |
| DML — Data Manipulation | the rows inside tables | INSERT, UPDATE, DELETE, (SELECT) |
| DCL — Data Control | who may do what | GRANT, REVOKE |
| TCL — Transaction Control | units of work | COMMIT, ROLLBACK, SAVEPOINT |
(Purists sometimes park SELECT in its own family, DQL — Data Query Language. Mention that footnote and collect the bonus mark.)
DDL — building and reshaping the building
CREATE TABLE students (
student_id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100) UNIQUE,
enrolled_date DATE DEFAULT (CURRENT_DATE)
);
ALTER TABLE students ADD COLUMN phone_number VARCHAR(15);
ALTER TABLE students CHANGE COLUMN phone_number contact_number VARCHAR(15);
DROP TABLE students; -- structure + data + indexes, all goneDDL statements change the schema — they define what exists. ALTER TABLE is the everyday workhorse: add a column, change a type, rename, add a constraint — all without recreating the table. Note DDL's personality trait for later: in MySQL, DDL statements implicitly commit. Pin that thought.
DML — working with the rows
-- the archival classic: copy between tables in one statement
INSERT INTO orders_archive (order_id, order_date, customer_name, amount)
SELECT order_id, order_date, customer_name, amount
FROM orders
WHERE order_date >= '2025-01-01' AND order_date < '2026-01-01';INSERT, UPDATE, DELETE — you've used them all course long. The combo above, INSERT … SELECT, is worth a special place in your toolkit: it moves data between tables in one statement and powers every archival and migration job you'll ever write. DML is row-level, logged, and rollback-able inside a transaction — which is exactly what distinguishes it from its DDL lookalike below.
DELETE vs TRUNCATE vs DROP — the eternal question
| DELETE | TRUNCATE | DROP | |
|---|---|---|---|
| Family | DML | DDL (despite feeling like DML!) | DDL |
| Removes | rows (WHERE-selectable) | ALL rows, keeps structure | the table itself |
| Speed | row by row — slow on crores | deallocates pages — fast | instant |
| Rollback (MySQL) | yes, inside a transaction | no — implicit commit | no — implicit commit |
| Auto-increment | keeps the counter | resets to 1 | counter gone with the table |
| Row triggers | fire per row | don't fire | — |
The line that wins the follow-up: TRUNCATE's rollback story depends on the database — MySQL and Oracle can't undo it (implicit commit), but SQL Server and PostgreSQL can roll it back inside an explicit transaction. "It depends — and here's exactly how" beats a memorised yes/no every time.
DCL — handing out (and taking back) the keys
GRANT SELECT ON orders TO analyst_ro; -- read-only access
REVOKE SELECT ON orders FROM analyst_ro; -- and it's goneGRANT and REVOKE manage privileges — SELECT, INSERT, UPDATE, DELETE, EXECUTE — per user or role, per object. Realistic patterns: a reporting user gets SELECT only; an application account gets SELECT + INSERT + UPDATE but never DROP. Add WITH GRANT OPTION and the grantee can pass the privilege onward — power that should be handed out rarely. DCL pairs beautifully with views: grant access to a view, and the base table's hidden columns don't exist for that user.
TCL — you already know it
COMMIT, ROLLBACK and SAVEPOINT got their own full lesson — Transactions & ACID. Here, just file them correctly: they control units of work, not data or structure — that's what makes them their own family and a favourite classification-question distractor.
Wait — the implicit-commit trap
START TRANSACTION;
UPDATE accounts SET balance = balance - 5000 WHERE account_id = 'A101';
-- teammate's migration script runs here:
ALTER TABLE accounts ADD COLUMN branch VARCHAR(30);
-- ⚠ MySQL just IMPLICITLY COMMITTED your uncommitted UPDATE
ROLLBACK; -- rolls back… nothing. The debit is already permanent.In MySQL, every DDL statement (CREATE, ALTER, DROP, TRUNCATE…) first commits whatever transaction is open — silently. Your planned "I'll roll back if step 3 fails" safety net evaporates without a single warning. The rule that follows: never mix DDL into the middle of a transaction. Schema changes go in their own scripts, run at their own time.
Common mistakes
- Classifying TRUNCATE as DML because it "deletes data" — it's DDL, and that's precisely why it behaves differently.
- Using DELETE without WHERE when you meant TRUNCATE (slow) — or TRUNCATE when you needed rollback (gone).
- Expecting the auto-increment counter to reset after DELETE — only TRUNCATE resets it.
- Running migrations (DDL) inside application transactions — implicit commit eats your rollback.
- Granting broad privileges "temporarily" and never revoking — audits exist, and they will find it.
Quick recap
| Idea | One-liner |
|---|---|
| DDL / DML / DCL / TCL | structure / rows / permissions / units of work |
| DELETE | row-by-row DML — WHERE-able, rollback-able, keeps counter |
| TRUNCATE | fast DDL wipe — resets counter; MySQL can't roll it back |
| DROP | the table itself ceases to exist |
| GRANT / REVOKE | privileges in, privileges out — least privilege wins |
| Implicit commit | MySQL DDL commits your open transaction — keep DDL out of them |
Practice Zone — PYQs from real selection rounds
INSERT belongs to which family of SQL commands?
Asked in


You want to remove ALL rows fast, reset the auto-increment counter, but keep the table structure. Which command?
Asked in


GRANT and REVOKE belong to which command family, and what do they manage?
Asked in


In MySQL (InnoDB), can TRUNCATE TABLE be rolled back?
Asked in


Mid-transaction (with uncommitted UPDATEs), you run ALTER TABLE … in MySQL. What happens to those pending UPDATEs?
Asked in


The orders table has an auto-increment order_id and currently holds 3 rows (next auto-increment value: 4). Write a single statement to remove all rows AND reset the counter back to 1 — and think about why DELETE FROM orders; wouldn't achieve the same.
Asked in


orders3 rows
| order_id | customer_name | amount |
|---|---|---|
| Asha Rao | 100.00 | |
| Ravi Kumar | 200.00 | |
| Meera Iyer | 150.00 |
Write a single INSERT ... SELECT statement that copies all orders placed in the year 2025 from the orders table into an orders_archive table of the same structure.
Asked in


orders3 rows
| order_id | order_date | customer_name | amount |
|---|---|---|---|
| 1 | 2025-03-10 | Asha Rao | 100.00 |
| 2 | 2026-01-05 | Ravi Kumar | 200.00 |
| 3 | 2025-11-20 | Meera Iyer | 150.00 |
orders_archive0 rows
| order_id | order_date | customer_name | amount |
|---|
Write a transaction that (1) deletes all of customer 101's orders with status 'CANCELLED' from orders, and (2) updates that customer's order_count in customers by subtracting the number of cancelled orders removed — committing only once both statements have run.
Asked in


customers1 row
| customer_id | name | order_count |
|---|---|---|
| 101 | Priya Nair | 5 |
orders4 rows
| order_id | customer_id | status |
|---|---|---|
| 1 | 101 | CANCELLED |
| 2 | 101 | CANCELLED |
| 3 | 101 | DELIVERED |
| 4 | 102 | CANCELLED |
FAQ
Is SELECT DML or DQL?
Both classifications exist. Many textbooks file SELECT under DML (it operates on data); stricter ones give it its own family — DQL, Data Query Language. In an interview, name both conventions and you can't be wrong.
Which is faster for emptying a huge table — DELETE or TRUNCATE?
TRUNCATE, massively — it deallocates the table's storage in one operation instead of logging crores of row deletions. The price: no WHERE, no rollback in MySQL, counter reset, row triggers skipped. If you need any of those, DELETE is the tool despite the cost.
I've finished all 12 lessons. What now?
Test yourself company-wise — the sidebar's Company-wise SQL PYQs section has real questions from TCS, Infosys, Amazon, Google and 14 more. Then re-do every Practice Zone cold after a week. If you can explain each answer aloud to a friend, you're interview-ready.
That's the full course. Now go practise company-wise — start with TCS SQL Interview Questions →


