Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
MySQL + SQL · Lesson 34

SQL Commands – DDL, DML, DQL, DCL, TCL

In this lesson: Types of SQL commands — DDL, DML, DQL, DCL, TCL — full list with examples and comparison table for exams.

SQL commands in groups

SQL has many commands, but they fall into five clear categories based on what they do. Learning these groups — DDL, DML, DQL, DCL, TCL — makes the whole language easier to understand, because each command's job becomes obvious from its group.

💡 DDL = structure, DML = change data, DQL = read data, DCL = permissions, TCL = transactions.

DDL — Data Definition Language

DDL commands define or change the structure of the database (tables, columns).

CREATE TABLE students (roll INT, name VARCHAR(50));
ALTER TABLE students ADD marks INT;
DROP TABLE students;

Main DDL commands: CREATE, ALTER, DROP, TRUNCATE. They shape the "containers" that hold data.

DML — Data Manipulation Language

DML commands change the data inside tables.

INSERT INTO students VALUES (1, 'Aman', 88);
UPDATE students SET marks = 90 WHERE roll = 1;
DELETE FROM students WHERE roll = 1;

Main DML commands: INSERT, UPDATE, DELETE. They add, modify and remove rows.

DQL — Data Query Language

DQL is about reading data. It has one main command:

SELECT name, marks FROM students WHERE marks > 40;

SELECT fetches data without changing anything, so it is safe to run any time. This is the command you will use most.

DCL — Data Control Language

DCL manages permissions — who can do what.

GRANT SELECT ON school.* TO 'user'@'localhost';
REVOKE INSERT ON school.* FROM 'user'@'localhost';

Main DCL commands: GRANT (give permission) and REVOKE (take it away). Used by administrators for security.

TCL — Transaction Control Language

TCL manages transactions — groups of changes that must all succeed or all fail.

START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;   -- or ROLLBACK to undo

Main TCL commands: COMMIT, ROLLBACK, SAVEPOINT. They keep related changes consistent, like a money transfer.

Summary table

CategoryPurposeCommands
DDLDefine structureCREATE, ALTER, DROP, TRUNCATE
DMLChange dataINSERT, UPDATE, DELETE
DQLRead dataSELECT
DCLPermissionsGRANT, REVOKE
TCLTransactionsCOMMIT, ROLLBACK, SAVEPOINT

Common mistakes

  • Confusing DDL and DML. DDL changes structure; DML changes data.
  • Thinking TRUNCATE is DML. It removes all rows but is DDL, and cannot be rolled back easily.
  • Forgetting COMMIT. In a transaction, changes are not final until you COMMIT.
  • Running DDL/DML carelessly in production. These change things; SELECT is the safe read-only one.

Summary

  • SQL commands fall into DDL, DML, DQL, DCL and TCL.
  • DDL defines structure (CREATE, ALTER, DROP).
  • DML changes data (INSERT, UPDATE, DELETE).
  • DQL reads data (SELECT); DCL controls permissions.
  • TCL manages transactions (COMMIT, ROLLBACK).

Next, use DDL in first commands, or compare removal commands in DROP vs TRUNCATE vs DELETE.

Frequently Asked Questions

What are the categories of SQL commands?
SQL commands are grouped into five categories: DDL (define structure), DML (change data), DQL (query data), DCL (control access), and TCL (manage transactions). Knowing which group a command belongs to helps you understand what it does.
What is the difference between DDL and DML?
DDL (Data Definition Language) changes the structure of the database — CREATE, ALTER, DROP tables. DML (Data Manipulation Language) changes the data inside tables — INSERT, UPDATE, DELETE. One shapes the container; the other fills it.
Is SELECT a DML or DQL command?
SELECT is usually classed as DQL (Data Query Language) because it only reads and returns data without changing it. Some books group it under DML, but treating querying as its own DQL group is clearer.
What do DCL and TCL do?
DCL (Data Control Language) manages permissions with GRANT and REVOKE, controlling who can do what. TCL (Transaction Control Language) manages transactions with COMMIT, ROLLBACK and SAVEPOINT, so groups of changes succeed or fail together.
Why is it useful to know these categories?
Grouping commands helps you learn SQL faster and reason about safety. For example, DDL and DML changes may need care in production, while DQL (SELECT) is read-only and safe to run freely.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.
Next topicMySQL Data Types Your progress: 34 / 151 (23%) · Lesson 35 / 151 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free