Types Of Sql Commands in SQL
SQL commands are categorized into several types based on their purpose. Here's a breakdown of the main types of SQL commands:
1. DDL (Data Definition Language)
Commands that define or modify the structure of database objects (tables, indexes, schemas, etc.).
Examples:
CREATE— Create tables, databases, views, etc.ALTER— Modify existing database objects.DROP— Delete tables, databases, or other objects.TRUNCATE— Remove all rows from a table quickly.RENAME— Rename database objects.COMMENT— Add comments to database objects.
2. DML (Data Manipulation Language)
Commands that manipulate data stored in the tables.
Examples:
SELECT— Retrieve data from tables.INSERT— Insert new rows into a table.UPDATE— Modify existing data.DELETE— Remove rows from a table.MERGE— UPSERT operation (insert or update).
3. DCL (Data Control Language)
Commands that control access and permissions to the database.
Examples:
GRANT— Give users access privileges.REVOKE— Remove access privileges.
4. TCL (Transaction Control Language)
Commands that manage transactions to ensure data integrity.
Examples:
COMMIT— Save transaction changes permanently.ROLLBACK— Undo transaction changes.SAVEPOINT— Set a point to which you can rollback.SET TRANSACTION— Set transaction properties.
5. Other categories (less common)
DQL (Data Query Language): Sometimes
SELECTis classified separately as DQL because it only queries data.Utility commands: Database-specific commands for maintenance or optimization (e.g.,
ANALYZE,EXPLAIN).
Summary Table
| Category | Purpose | Common Commands |
|---|---|---|
| DDL | Define/modify database structure | CREATE, ALTER, DROP |
| DML | Manipulate data | SELECT, INSERT, UPDATE, DELETE |
| DCL | Control access/permissions | GRANT, REVOKE |
| TCL | Manage transactions | COMMIT, ROLLBACK, SAVEPOINT |
If you'd like, I can explain any of these commands in detail or provide examples!