✏️ Explanatory Question

What are the different types of SQL commands (DDL, DML, DCL, TCL, DQL)?

👁 9 Views
📘 Detailed Answer
🟢 Easy
💡

Answer with Explanation

4

What are the different types of SQL commands?

Level: Basic — A must-know classification question; interviewers expect all five categories.

SQL commands are grouped into five main categories based on what they do. Remembering these categories shows you understand how SQL is organized.

The Five Categories

  • DDL (Data Definition Language): Defines and modifies database structure — CREATE, ALTER, DROP, TRUNCATE, RENAME.
  • DML (Data Manipulation Language): Manages data inside tables — INSERT, UPDATE, DELETE.
  • DQL (Data Query Language): Retrieves data — SELECT.
  • DCL (Data Control Language): Controls access & permissions — GRANT, REVOKE.
  • TCL (Transaction Control Language): Manages transactions — COMMIT, ROLLBACK, SAVEPOINT.
Common trap: TRUNCATE is a DDL command (not DML), because it deallocates the data pages rather than deleting rows one by one — that's why it can't be rolled back and doesn't fire triggers.

Quick Reference Table

Category Full Form Commands Auto-Commit?
DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE Yes
DML Data Manipulation Language INSERT, UPDATE, DELETE No
DQL Data Query Language SELECT No
DCL Data Control Language GRANT, REVOKE Yes
TCL Transaction Control Language COMMIT, ROLLBACK, SAVEPOINT

Quick Example of Each Type

-- DDL: define structure
CREATE TABLE students (id INT, name VARCHAR(50));

-- DML: manipulate data
INSERT INTO students VALUES (1, 'Rumman');
UPDATE students SET name = 'Ansari' WHERE id = 1;

-- DQL: query data
SELECT * FROM students;

-- DCL: control access
GRANT SELECT ON students TO 'app_user'@'localhost';

-- TCL: manage transaction
COMMIT;
Interviewer tip: If they ask only for the "main" types, mention DDL, DML, DCL, and TCL — then score bonus points by adding DQL (SELECT) as a separate category.