Database Languages (DDL, DML, DCL, TCL)

Database languages are the sub-languages that make up SQL, each handling a different kind of task. DDL (Data Definition Language) defines structure, DML (Data Manipulation Language) works with the data inside tables, DCL (Data Control Language) manages permissions with GRANT and REVOKE, and TCL (Transaction Control Language) manages transactions.

4 min read

SQL is often talked about as one language, but it's actually made up of several distinct sub-languages, each responsible for a different kind of task. Knowing which commands belong to which category makes it much easier to reason about what a given SQL statement is actually doing to the database.

DDL: Data Definition Language

DDL commands define or change the structure of the database itself, tables, columns, indexes, constraints, not the data inside them.

  • CREATE: creates a new table, database, index, or other object.
  • ALTER: modifies an existing object's structure, like adding a new column to a table.
  • DROP: permanently deletes an object and everything inside it.
  • TRUNCATE: removes all rows from a table, but keeps the table structure itself intact.

DDL statements typically auto-commit immediately in most databases; there's usually no "undo" once one runs.

DML: Data Manipulation Language

DML commands work with the actual data inside tables, not the structure.

  • SELECT: retrieves data.
  • INSERT: adds new rows.
  • UPDATE: modifies existing rows.
  • DELETE: removes rows.

Unlike DDL, DML operations typically happen inside a transaction and can be rolled back if something goes wrong before a commit.

DCL: Data Control Language

DCL commands manage permissions, who is allowed to do what.

  • GRANT: gives a user or role a specific permission, like the ability to SELECT from a table.
  • REVOKE: removes a previously granted permission.

TCL: Transaction Control Language

TCL commands manage the boundaries of a transaction, a group of operations that should succeed or fail together.

  • BEGIN (or START TRANSACTION): starts a new transaction.
  • COMMIT: makes all changes made during the transaction permanent.
  • ROLLBACK: undoes all changes made since the transaction began.
  • SAVEPOINT: marks a point within a transaction that a later rollback can return to, without undoing the entire transaction.

A worked example

Setting up a new products table and controlling who can touch it uses commands from all four categories:

-- DDL: define the structure
CREATE TABLE products (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  price DECIMAL(10, 2)
);

-- DCL: control access
GRANT SELECT, INSERT ON products TO app_user;

-- TCL + DML: a transaction that inserts a product, only kept if both steps succeed
BEGIN;
INSERT INTO products (id, name, price) VALUES (1, 'Keyboard', 49.99);
INSERT INTO inventory_log (product_id, action) VALUES (1, 'created');
COMMIT;

If the second INSERT had failed for some reason (say a constraint violation on inventory_log), a ROLLBACK instead of COMMIT would undo the first INSERT too, so the database never ends up with a product that has no matching inventory log entry.

Where this matters in real systems

In real production systems, DDL changes (like adding a column) are usually run separately from application code, often through migration tools, and reviewed carefully since they can lock tables or be hard to reverse. DML runs constantly as the application serves normal traffic. DCL is central to security audits, verifying exactly which roles can read or write which tables. TCL is what makes multi-step operations, like the e-commerce checkout example common across ACID discussions, actually safe to run concurrently without corrupting data.

What interviewers actually ask about SQL's sub-languages

  • "What's the difference between DDL and DML?" DDL changes structure (tables, columns); DML changes the data inside that structure (rows).
  • "Is TRUNCATE DDL or DML, and why does that matter?" It's DDL, which is why it typically can't be rolled back the way a DML DELETE can, and why it resets auto-increment counters while DELETE doesn't.
  • "What do GRANT and REVOKE do?" They're DCL commands that add or remove a specific permission for a user or role.
  • "Why would you wrap multiple DML statements in a transaction?" So they succeed or fail together, preserving data consistency, which is the same reasoning behind atomicity.

Key takeaways

  • DDL (CREATE, ALTER, DROP, TRUNCATE) defines or changes database structure.
  • DML (SELECT, INSERT, UPDATE, DELETE) works with the data inside that structure.
  • DCL (GRANT, REVOKE) manages who has permission to do what.
  • TCL (BEGIN, COMMIT, ROLLBACK, SAVEPOINT) manages transaction boundaries.
  • DDL typically auto-commits immediately; DML can usually be rolled back within a transaction.
All 174 DBMS interview questions

Log in to save which topics you've read across every subject.

Frequently asked questions

What's the difference between DDL and DML?

DDL changes structure (tables, columns); DML changes the data inside that structure (rows).

Is `TRUNCATE` DDL or DML, and why does that matter?

It's DDL, which is why it typically can't be rolled back the way a DML `DELETE` can, and why it resets auto-increment counters while `DELETE` doesn't.

What do `GRANT` and `REVOKE` do?

They're DCL commands that add or remove a specific permission for a user or role.

Why would you wrap multiple DML statements in a transaction?

So they succeed or fail together, preserving data consistency, which is the same reasoning behind atomicity.