What are DDL, DML, DCL and TCL commands?
EasyConceptDBMS Fundamentals
Answer
SQL commands are grouped into four families according to what they act on: the structure, the data, the permissions or the transactions.
- DDL (Data Definition Language) defines or changes structure:
CREATE,ALTER,DROP,TRUNCATE,RENAME. - DML (Data Manipulation Language) works with the rows inside tables:
INSERT,UPDATE,DELETEandSELECT. Some books putSELECTin a separate DQL (Data Query Language) group. - DCL (Data Control Language) manages permissions:
GRANT,REVOKE. - TCL (Transaction Control Language) manages transactions:
COMMIT,ROLLBACK,SAVEPOINT.
In MySQL and Oracle, a DDL statement commits the current transaction automatically, so it cannot be rolled back. PostgreSQL can roll back most DDL inside a transaction.
Example:
CREATE TABLE marks (roll INT, score INT); -- DDL
INSERT INTO marks VALUES (1, 85); -- DML
GRANT SELECT ON marks TO teacher; -- DCL
COMMIT; -- TCL