Different Types of command in SQL - DDL, DML & DCL

SQL commands are broadly categorized into three main types, each serving a distinct purpose in the database ecosystem:

  1. DDL (Data Definition Language) Commands:

    DDL commands focus on defining and managing the structure of the database. They enable you to create, modify, and delete database objects such as tables, indexes, and schemas. Examples of DDL commands include CREATE, ALTER, and DROP.

  2. DML (Data Manipulation Language) Commands:

    DML commands are concerned with the manipulation of data within the database. They allow you to retrieve, add, modify, and delete data from tables. Commonly used DML commands include SELECT, INSERT, UPDATE, and DELETE.

  3. DCL (Data Control Language) Commands:

    DCL commands deal with managing access and permissions within the database. They grant or revoke specific privileges to users. Examples of DCL commands are GRANT and REVOKE.

The Significance of SQL Commands

SQL commands are the building blocks of any database interaction. Whether you’re creating a new table, querying data, or controlling user access, SQL commands empower you to perform a myriad of operations with precision and efficiency. Mastering these commands is key to becoming proficient in database management.

Difference between DDL, DML and DCL

AspectDDL (Data Definition Language)DML (Data Manipulation Language)DCL (Data Control Language)
PurposeDefines and manages the structure of the databaseManipulates data stored in the database tablesControls access and permissions within the database
OperationsCREATE, ALTER, DROP, TRUNCATE, COMMENT, RENAMESELECT, INSERT, UPDATE, DELETEGRANT, REVOKE
ExamplesCREATE TABLE, ALTER TABLE, DROP TABLESELECT * FROM table_name WHERE condition; INSERT INTO table_name VALUES (values); UPDATE table_name SET column1 = value WHERE condition; DELETE FROM table_name WHERE condition;GRANT SELECT ON table_name TO user_name; REVOKE INSERT ON table_name FROM user_name;
Impact on DataAlters the structure of the databaseModifies or retrieves data from the databaseManages user access and permissions on data in the database
Transactions and RollbackTypically involves implicit COMMITInvolves explicit COMMIT and ROLLBACK statementsMay be involved in transaction control through GRANT and REVOKE
Example Use CasesCreating or modifying tables, indexes, etc.Retrieving, adding, modifying, or deleting records in tablesManaging access permissions for different users in a multi-user system
Key CommandsCREATE TABLE, ALTER TABLE, DROP TABLESELECT, INSERT, UPDATE, DELETEGRANT, REVOKE