SQL: Structured Query LanguageSQL FundamentalsSQL Command Categories

What are the main categories of SQL commands?

Question 9 of 30 · Updated

On this page

The main categories of SQL commands are DDL (Data Definition Language), DML (Data Manipulation Language), DQL (Data Query Language), DCL (Data Control Language), and TCL (Transaction Control Language). These categories group statements by their primary purpose: defining database structures, changing data, retrieving data, controlling access, and managing transactions.

This five-category classification is a common teaching and interview convention, not a universally exclusive classification defined identically by every database product. Some references classify SELECT as part of DML rather than treating DQL as a separate category. The important distinction is what each statement does.

1. SQL command categories at a glance#

CategoryFull formPrimary purposeCommon examples
DDLData Definition LanguageDefine or change database objectsCREATE, ALTER, DROP, TRUNCATE
DMLData Manipulation LanguageInsert, modify or remove stored rowsINSERT, UPDATE, DELETE, MERGE
DQLData Query LanguageRetrieve or compute dataSELECT
DCLData Control LanguageGrant or revoke access privilegesGRANT, REVOKE
TCLTransaction Control LanguageManage transaction boundaries and outcomesBEGIN, COMMIT, ROLLBACK, SAVEPOINT

Think of a library application: DDL creates the books table, DML records new books and changes stock, DQL retrieves available books, DCL controls who can access the table, and TCL ensures a group of changes is committed or undone together.

2. DDL — Data Definition Language#

DDL defines database objects and their structure. Creating a table establishes column names, data types and constraints; altering a table changes its definition. DROP removes an object, and TRUNCATE removes all rows from a table while preserving the table definition. TRUNCATE is commonly taught under DDL, although it operates on data and its classification and transaction behavior vary across products.

Use a fresh, disposable database for the following examples. Do not run them against an existing production library database.

SQL
CREATE TABLE books ( book_id INTEGER PRIMARY KEY, title TEXT NOT NULL, copies INTEGER NOT NULL CHECK (copies >= 0) ); ALTER TABLE books ADD COLUMN shelf TEXT;

The first statement creates a table with three columns. The second adds a nullable fourth column named shelf. No book records have been added yet; DDL can define a structure independently of the stored data.

To demonstrate removing an object without destroying the main example, create and drop a separate scratch table:

SQL
CREATE TABLE scratch (id INTEGER); DROP TABLE scratch;

After DROP TABLE, the scratch table no longer exists. DROP can remove both a table definition and its data, and may be blocked by dependencies. Review dependencies, permissions and backups before destructive schema changes. Do not assume all DDL automatically commits: PostgreSQL supports rollback of many DDL operations in transactions, whereas some other engines implicitly commit many DDL statements.

3. DML — Data Manipulation Language#

DML changes the data stored in existing tables. Common commands include INSERT to add records, UPDATE to modify records, DELETE to remove records, and MERGE to perform conditional changes in engines that support it.

Continue using the books table created above:

SQL
INSERT INTO books (book_id, title, copies) VALUES (1, 'SQL Basics', 3), (2, 'Data Modeling', 1);

The table now contains two book records:

book_idtitlecopies
1SQL Basics3
2Data Modeling1

Update the number of copies of book 1 and remove book 2:

SQL
UPDATE books SET copies = 4 WHERE book_id = 1; DELETE FROM books WHERE book_id = 2;

Each statement affects one row in this example. Neither changes the table's column definitions. Constraints still apply to DML operations; for example, a negative number of copies violates the CHECK constraint.

Safety: UPDATE or DELETE without an appropriate WHERE condition can affect every row. Before modifying production data, verify the target rows, expected affected-row count and transaction strategy. A successful command does not necessarily mean a row was changed: a WHERE predicate might match nothing.

4. DQL — Data Query Language#

DQL is the common teaching label for SQL statements that retrieve or compute information. SELECT can return columns, filter rows, combine tables, aggregate values and calculate expressions.

SQL
SELECT book_id, title, copies FROM books WHERE copies > 0 ORDER BY book_id;

After the preceding DML statements, the output is:

book_idtitlecopies
1SQL Basics4

This ordinary SELECT reads the available inventory without changing the stored records. Some SQL references include SELECT in DML because it manipulates information in the broader sense. In interviews, you can describe DQL as the retrieval subset in the familiar five-category teaching model.

Do not infer the category solely from the presence of a result set. PostgreSQL's INSERT, UPDATE and DELETE can also return rows using RETURNING. Conversely, some SELECT statements invoke functions with side effects or acquire locks, so SELECT is not an unconditional guarantee of harmless execution.

5. DCL — Data Control Language#

DCL controls database access through privileges. GRANT assigns a privilege to a role, and REVOKE removes a grant. Database authorization is different from changing the data itself.

The following PostgreSQL-specific example assumes a newly created, dedicated role named library_reader, no other grants or role memberships, and an administrator operating in a disposable database. These DCL commands are illustrative and were not executed:

SQL
CREATE ROLE library_reader NOLOGIN; GRANT USAGE ON SCHEMA public TO library_reader; GRANT SELECT ON TABLE public.books TO library_reader; REVOKE SELECT ON TABLE public.books FROM library_reader;

CREATE ROLE is setup DDL or an administrative command; the GRANT and REVOKE statements demonstrate DCL. The table must exist in the public schema for the example. USAGE allows access to objects in the namespace subject to individual object permissions. SELECT grants table-read permission, but does not by itself grant INSERT, UPDATE or DELETE. REVOKE removes the direct SELECT grant; other privileges from PUBLIC, role memberships, ownership or other grants can still affect effective access.

SQLite does not provide PostgreSQL-style GRANT/REVOKE or database roles, so this section cannot be tested in SQLite. In Supabase and other API-backed systems, grants and row-level security are separate layers; use least-privilege grants and appropriate row-level policies for exposed tables. The role here is a hypothetical dedicated teaching role, not an anonymous or authenticated application role. No actual role or privilege configuration was modified for this lesson.

6. TCL — Transaction Control Language#

TCL manages transactions, which are logical units of work that can contain multiple statements. BEGIN (or START TRANSACTION in supporting systems) opens a transaction, COMMIT makes its changes committed, ROLLBACK undoes its uncommitted changes, and SAVEPOINT creates a marker to which a transaction can partially roll back.

Suppose the library currently has four copies of SQL Basics. A transaction attempts two stock reductions but cancels the second one:

SQL
BEGIN; UPDATE books SET copies = copies - 1 WHERE book_id = 1; SAVEPOINT before_second_change; UPDATE books SET copies = copies - 1 WHERE book_id = 1; SELECT copies FROM books WHERE book_id = 1; ROLLBACK TO SAVEPOINT before_second_change; RELEASE SAVEPOINT before_second_change; SELECT copies FROM books WHERE book_id = 1; COMMIT; SELECT copies FROM books WHERE book_id = 1;
Point in the transactionCopies
Before BEGIN4
After both reductions2
After rollback to savepoint3
After COMMIT3

The two UPDATE commands are DML; the SELECT commands are DQL; BEGIN, SAVEPOINT, ROLLBACK TO, RELEASE and COMMIT are TCL. One transaction can contain statements from multiple categories. COMMIT preserves the first reduction; the second is undone. A savepoint is not a separate committed transaction.

Now demonstrate a full rollback:

SQL
BEGIN; UPDATE books SET copies = 0 WHERE book_id = 1; ROLLBACK; SELECT copies FROM books WHERE book_id = 1;

The result is still 3 because the uncommitted update was undone. A rollback does not normally undo an already committed transaction. Transaction and DDL semantics vary between products, and many clients use autocommit unless an explicit transaction is started.

Production caveat: The library example illustrates transaction boundaries, not a complete book checkout system. A real application would need concurrency control, correct stock validation, reservation or checkout records, and error handling.

7. DELETE vs TRUNCATE vs DROP#

These are frequently confused because they all can remove data.

CommandTypical categoryEffectWHERE filter?Table remains?
DELETEDMLDeletes matching rows, or all rows without a filterYesYes
TRUNCATECommonly DDLRemoves all rows from specified tablesNoYes
DROP TABLEDDLRemoves the table object and its dataNoNo

In PostgreSQL, TRUNCATE can be rolled back if the containing transaction is rolled back, and it has different locking, foreign-key and trigger behavior from DELETE. Other engines may implicitly commit it. SQLite does not support TRUNCATE TABLE. The TRUNCATE comparison is conceptual and was not executed. Never choose between these commands using only a generic speed claim; consider desired semantics and engine-specific behavior.

8. Testing and verification#

The executable DDL, DML, DQL and TCL examples were tested using SQLite 3.46.1 in an isolated in-memory database with explicit transaction control. Ten assertions passed: added-column metadata, inserted records, UPDATE and DELETE row counts, filtered SELECT output, state before savepoint rollback, state after rollback to savepoint, committed state, full rollback state, and removal of the scratch table.

The examples use common SQL syntax intended to work in PostgreSQL as well. PostgreSQL execution of the DDL, DML, DQL and TCL examples was not independently performed. The PostgreSQL-specific DCL commands and discussion of TRUNCATE are clearly marked as untested. No educational DDL, DML or privilege changes were executed against production tables.

9. Interview-ready answer#

SQL commands are commonly grouped into five categories. DDL defines or changes database structures using CREATE, ALTER and DROP. DML changes stored data using INSERT, UPDATE and DELETE. DQL retrieves information using SELECT. DCL manages permissions through GRANT and REVOKE. TCL controls transactions through BEGIN, COMMIT, ROLLBACK and SAVEPOINT. These categories describe the main purpose of the statement rather than its implementation. Some classifications include SELECT under DML, and transaction behavior differs across database engines.

Quick interview follow-ups#

  • Is SELECT DML or DQL? Both conventions exist: DQL is a common separate teaching category, while broader DML classifications include SELECT.
  • Does DELETE remove a table? No. It removes rows; DROP TABLE removes the table itself.
  • Is COMMIT a DML command? No. It controls a transaction that may contain DML statements.
  • Does DDL always auto-commit? No. It depends on the database and specific operation.
  • Are GRANT and REVOKE supported in every SQL engine? No. Authorization mechanisms differ across products.

Related questions

Explore other topics:Forward Deployed EngineeringPythonAI System DesignMachine Learning

Machinoai Logo
Machinoai

Your edge in the AI era. Deep dives into machine learning concepts, paper explainers, verified industry jobs, and developer tools.

© 2026 Machinoai. All rights reserved.