Skip to content
Reference notes from the interactive SQL course, which covers the same ground with a live SQL console, graded challenges and a final exam.
Getting Started

SQL Command Categories (DDL/DML/DCL/DQL)

Every SQL keyword belongs to one of four families. Learn them once, never confuse them again.

SQL Command Categories

There are dozens of SQL keywords. Memorizing them is pointless. Grouping them into four families makes them stick.

The four families

FamilyWhat it doesKeywords you'll see
DDL — Data Definition LanguageDefines the SHAPE of your data (creates / changes / removes tables)CREATE, ALTER, DROP, TRUNCATE, RENAME
DML — Data Manipulation LanguageChanges the CONTENT of your data (rows in/out)INSERT, UPDATE, DELETE, MERGE
DCL — Data Control LanguageManages PERMISSIONS (who can do what)GRANT, REVOKE
DQL — Data Query LanguageReads data (the most common one by far)SELECT

Some textbooks also list TCL — Transaction Control Language (COMMIT, ROLLBACK, SAVEPOINT) as a fifth family. We'll cover transactions in Module 9.

Why this grouping matters

It tells you what the command affects and how dangerous it is:

  • DDL changes the structure — affects every row in a table at once. Hard to reverse. Big risk.
  • DML changes rows — affects specific rows. Reversible via transactions before commit.
  • DCL changes who-can-do-what — affects security. Production teams audit this.
  • DQL just reads — zero risk. The only family safe to run on production without a second pair of eyes.

When you see a query, ask: which family? If it's DDL, slow down. If it's DQL, just run it.

Each family in one example

DDL — define structure

CREATE TABLE customers (
  id INT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255) UNIQUE
);

This creates a new table. Until you run an INSERT, the table has zero rows.

DML — change content

INSERT INTO customers (id, name, email)
VALUES (1, 'Anita Rao', 'anita@example.com');

This adds one row to the existing table.

DCL — control access

GRANT SELECT ON customers TO analytics_user;

This gives the analytics_user role permission to read from the customers table, but not write.

DQL — read

SELECT name, email FROM customers WHERE id = 1;

This reads one row matching id = 1. Returns Anita Rao / anita@example.com.

A common interview trap

"What's the difference between DELETE and TRUNCATE?"

Both empty out a table. The trick:

DELETETRUNCATE
DML — manipulates rowsDDL — redefines table
Row by rowWhole table at once
Logs each row deletionDoesn't log individual rows (faster)
Can have a WHERE clauseAll-or-nothing
Can be rolled back inside a transactionCan't always be rolled back
Triggers fireTriggers do NOT fire

DELETE is surgical. TRUNCATE is a wrecking ball. Same end state, very different mechanics.

Cheat sheet to bookmark

DDL → defines structure         CREATE / ALTER / DROP / TRUNCATE
DML → changes content           INSERT / UPDATE / DELETE
DCL → manages permissions       GRANT / REVOKE
DQL → reads data                SELECT
TCL → transaction control       COMMIT / ROLLBACK / SAVEPOINT

Print this and tape it to your monitor for week one of any SQL job.

Module 1 complete 🎉

You now know:

  • ✅ What SQL is and why it's worth learning
  • ✅ Real-world scenarios where SQL is the answer
  • ✅ What an RDBMS is and the major players
  • ✅ Tables, rows, columns, fields, NULL
  • ✅ The four families of SQL commands

In Module 2: SQL Databases, we'll do a quick tour of the major RDBMS systems — MySQL, PostgreSQL, SQLite, MS SQL Server, Oracle — and help you pick which one to install for hands-on practice.

All 43 lessons in SQL — The Interactive Visual Notebook
  1. Introduction to SQL
  2. Why SQL Matters
  3. What is an RDBMS?
  4. Tables, Rows, and Columns
  5. SQL Command Categories (DDL/DML/DCL/DQL)
  6. SELECT and FROM
  7. Aliases and Expressions
  8. DISTINCT and Sorting
  9. Limiting Results
  10. Query Execution Order
  11. WHERE and Comparison Operators
  12. Combining Conditions — AND, OR, NOT
  13. IN, BETWEEN, and LIKE
  14. Working with NULL
  15. Aggregate Functions
  16. GROUP BY
  17. HAVING — Filtering Groups
  18. Grouping in Practice
  19. INNER JOIN
  20. LEFT JOIN and Outer Joins
  21. Self Joins
  22. Cross Joins and Join Pitfalls
  23. UNION, INTERSECT, and EXCEPT
  24. Subqueries
  25. EXISTS and Correlated Subqueries
  26. Common Table Expressions (WITH)
  27. Recursive CTEs
  28. Window Functions — The OVER Clause
  29. Ranking Functions
  30. Frames and Running Totals
  31. LAG and LEAD
  32. Window Function Patterns
  33. What an Index Is
  34. Reading a Query Plan
  35. Designing Indexes
  36. Writing Queries an Index Can Use
  37. Transactions and ACID
  38. Isolation Levels
  39. Locks and Deadlocks
  40. Choosing Data Types
  41. Constraints and Keys
  42. Normalisation
  43. Designing a Schema