SQL Statements: DDL Statements, DML Statements, DCL Statements, TCL Statements
SQL statements are grouped into functional categories that define how we interact with the database—from building its structure to managing user permissions.
1. DDL (Data Definition Language)
These commands change the “blueprint” of the database. They are typically auto-committed, meaning changes are saved immediately and cannot be undone.
CREATE: Building new tables, views, or databases.ALTER: Modifying existing structures, such as adding a column to a table.DROP: Deleting an entire object (table and all its data) permanently.TRUNCATE: Removing all rows from a table while keeping the empty structure intact.
2. DML (Data Manipulation Language)
These commands allow you to work with the actual records. Unlike DDL, these are usually not auto-committed and can be rolled back before they are finalized.
INSERT: Adding new records into a table.UPDATE: Modifying existing data within rows.DELETE: Removing specific rows based on a condition.
3. DCL (Data Control Language)
Mainly used by Database Administrators to control who can perform specific actions.
GRANT: Giving a user specific permissions (e.g., permission to read a table).REVOKE: Taking away previously granted permissions.
4. TCL (Transaction Control Language)
These commands wrap around DML statements to manage their execution as a single “unit of work”.
COMMIT: Saving all changes made during the current transaction permanently.ROLLBACK: Undoing changes made since the last commit if an error occurs.SAVEPOINT: Setting a checkpoint within a transaction to which you can partially roll back.