SQL Sublanguages (DDL, DML, DCL)
Context: FIT2094_MOC · SQL split by what it acts on · structure (DDL) vs data (DML) vs access (DCL) · the physical-design language on Oracle
Quick Revision
- 🎯 Objective: classify every SQL statement as DDL / DML / DCL ➔ predict its keywords and its commit behaviour.
- ⚡ Key Constraint: DDL auto-commits (permanent on execution); DML is transactional (
COMMIT/ROLLBACK) — never writeCOMMITfor DDL.
📝 Core
- DDL — define structure ➔
CREATE,ALTER,DROPon tables/constraints; auto-committed immediately, noCOMMIT/ROLLBACK. - DML — change/read data ➔
INSERT,UPDATE,DELETE(writes) +SELECT(read); writes are not saved untilCOMMIT, reversible byROLLBACK. - DCL — manage access ➔
GRANT,REVOKEobject privileges to users, e.g.GRANT SELECT ON customer TO abc001;. - SELECT is inert ➔
SELECT * FROM unit;changes neither structure nor data.
⚠️ Common Mistakes
- 💡 Never
COMMIT/ROLLBACKa DDL statement ➔ DDL is already permanent on execution; adding a transaction control command is wrong for this unit. - 💡
DELETE(DML) ≠DROP(DDL) ➔DELETEremoves rows (reversible pre-commit);DROPremoves the table structure (auto-committed).
🧠 Active Recall
Why can you
ROLLBACKanINSERTbut not aCREATE TABLE?Answer
- Short answer:
INSERTis DML — pending untilCOMMIT, so reversible;CREATE TABLEis DDL — auto-committed on execution.- Why: Transaction boundary ➔ DDL implicitly commits the current transaction, discarding any rollback point.