SQL statements perform different jobs: defining database objects, changing rows, retrieving data, managing permissions, and controlling transactions. Classifying them makes SQL easier to learn and helps you choose the right kind of statement.
Key Takeaways at a Glance:
- •DDL (Data Definition Language) commands (CREATE, ALTER, DROP, TRUNCATE) define schemas and auto-commit in most engines.
- •DML (Data Manipulation Language) commands (INSERT, UPDATE, DELETE) mutate table data rows inside transactions.
- •DQL (Data Query Language) consists of SELECT to read records without altering database state.
- •TCL (Transaction Control Language) manages transaction state (COMMIT, ROLLBACK, SAVEPOINT).
In Simple Words (The Mental Model)
SQL commands are grouped by what they touch. DDL builds the house (walls, rooms, doors). DML moves furniture inside the rooms. DQL looks through the window to see what furniture is inside. TCL decides whether to lock the doors and save changes or undo everything back to the beginning.
Real-World Analogy
Think of a physical bank ledger book. Designing the columns on the page ('Date, Payee, Debit, Credit') is DDL. Writing a deposit line in pencil is DML. Reading your account balance is DQL. Erasing the pencil entry before signing is ROLLBACK (TCL), and signing it in permanent ink is COMMIT (TCL).