Learn SQL
-- fundamentals.sublanguages_dialects

Sublanguages & Dialects (DDL/DML/DCL/TCL) in SQL

One language, four jobs — plus vendor dialects

--concept

SQL splits into DDL (CREATE/ALTER/DROP — structure), DML (SELECT/INSERT/UPDATE/DELETE — rows), DCL (GRANT/REVOKE — permissions) and TCL (COMMIT/ROLLBACK/SAVEPOINT — transactions). Core SELECT/WHERE/GROUP BY/JOIN transfers everywhere; functions, upsert syntax and quoting vary by engine (PostgreSQL, MySQL, SQLite, SQL Server, Oracle).

--how it works
1

DDL shapes structure

CREATE/ALTER/DROP define tables, columns, constraints. Versioned migration files carry these.

2

DML moves rows

SELECT reads; INSERT/UPDATE/DELETE write. The daily 95% of statements.

3

DCL + TCL guard and group

GRANT/REVOKE gate access per role. BEGIN/COMMIT/ROLLBACK bundle writes atomically.

4

Dialects diverge at edges

Core transfers; upsert, quoting, functions and paging spellings vary — check the engine manual.

--visualization
DDLCREATE TABLEstructureDMLSELECT / INSERTrowsDCLGRANT / REVOKEpermissionsTCLCOMMIT / ROLLBACKtransactions
Stage 1 / 1
DML: SELECT / INSERT — rows. Upsert spelling splits by dialect: ON CONFLICT (PG) vs ON DUPLICATE KEY (MySQL).
--example
query.sql
1CREATE TABLE t (id INT PRIMARY KEY); -- DDL
2INSERT INTO t VALUES (1); -- DML
3GRANT SELECT ON t TO analyst; -- DCL
4COMMIT; -- TCL
Result
sublanguagejob
DDLstructure
DMLrows
DCLpermissions
TCLtransactions

Four statements, four jobs. Interviewers often ask for one verb per letter — have CREATE, SELECT, GRANT, COMMIT ready.

--variants

One verb per letter

Have CREATE, SELECT, GRANT, COMMIT ready for the interview.

query.sql
1CREATE TABLE t (id INT PRIMARY KEY);
2INSERT INTO t VALUES (1);
3GRANT SELECT ON t TO analyst;
4COMMIT;
Result
sublanguageverb
DDLCREATE TABLE
DMLINSERT
DCLGRANT
TCLCOMMIT
1DDL runs once per schema change, versioned.
2DML runs millions of times daily.
3DCL/TCL decide who may run DML and whether it sticks.

Same job, two spellings

Upsert syntax is the canonical dialect split.

query.sql
1-- PostgreSQL/SQLite:
2INSERT INTO counters (k,n) VALUES ('hits',1) ON CONFLICT (k) DO UPDATE SET n = counters.n + 1;
3-- MySQL:
4-- INSERT INTO counters (k,n) VALUES ('hits',1) ON DUPLICATE KEY UPDATE n = n + 1;
Result
enginespelling
PostgreSQL/SQLiteON CONFLICT
MySQLON DUPLICATE KEY
1Both need a UNIQUE constraint to conflict on.
2Both are atomic — no select-then-insert race.
3Portability rule: isolate dialect bits behind one helper.
--key facts
DDLCREATE · ALTER · DROP
DML vs TCLDML changes rows; TCL decides whether the change sticks
Portabilitycore queries transfer; functions/quoting/upsert vary
--use cases
Interview opener: sublanguage taxonomy with one verb each
Porting queries across PG/MySQL/SQLite — quarantining dialect bits
--under the hood
DCL is enforced at parse/plan time per role — least-privilege roles contain injection blast radius.
TCL durability rides the write-ahead log; COMMIT is a log flush, not just a flag.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Take the queries you just visualized and see the data structures that power real databases.