Overview of DML , DDL, TCL,DCL
The Four SQL Command Categories
- DDL (Data Definition Language): defines and modifies database structure — CREATE, ALTER, DROP, TRUNCATE, RENAME.
- DML (Data Manipulation Language): manipulates the actual data within tables — INSERT, UPDATE, DELETE, MERGE.
- TCL (Transaction Control Language): manages transactions — COMMIT, ROLLBACK, SAVEPOINT.
- DCL (Data Control Language): manages access and permissions — GRANT, REVOKE.
Why the Distinction Matters
Understanding which category a statement belongs to clarifies its effect: DDL changes structure and auto-commits in most databases, DML changes data and can typically be rolled back until committed, and TCL explicitly controls when those changes become permanent.
All Four Categories in One Test-Setup Script
Seeing the categories side by side in a realistic script makes the difference clear. Here is how a tester might prepare a small orders table, load data, check access and clean up:
-- DDL: build the structure
CREATE TABLE orders (
id INT PRIMARY KEY,
customer VARCHAR(50) NOT NULL,
amount DECIMAL(10,2),
status VARCHAR(20) DEFAULT 'NEW'
);
ALTER TABLE orders ADD created_at TIMESTAMP;
-- DML: work with the data
INSERT INTO orders (id, customer, amount) VALUES (1, 'Neha', 1200.00), (2, 'Arjun', 450.50);
UPDATE orders SET status = 'SHIPPED' WHERE id = 1;
DELETE FROM orders WHERE amount < 500;
-- DQL: read the data (often grouped with DML)
SELECT id, customer, status FROM orders;
-- DCL: control who can do what
GRANT SELECT ON orders TO qa_readonly;
REVOKE INSERT, UPDATE ON orders FROM qa_readonly;
-- TCL: decide whether changes stay
COMMIT;
Some textbooks list SELECT under DML, while others give it a fifth category, DQL (Data Query Language). Both views are common, so you may see either in interviews or documentation.
Quick Comparison Table
| Category | Works on | Can be rolled back? | Typical user |
|---|---|---|---|
| DDL | Tables, columns, indexes, views | Usually not in MySQL and Oracle; often yes in PostgreSQL and SQL Server inside a transaction | Developers, DBAs |
| DML | Rows of data | Yes, until committed | Applications, testers |
| DCL | User and role permissions | Depends on the database | DBAs, security teams |
| TCL | The current transaction | It is the rollback mechanism | Anyone changing data |
DELETE, TRUNCATE and DROP: a favourite interview question
| Command | Category | What it removes | Key behaviour |
|---|---|---|---|
DELETE | DML | Chosen rows, or all rows if no WHERE | Row by row, fires delete triggers, can be rolled back |
TRUNCATE | DDL | All rows, keeping the table | Fast, no WHERE clause, usually resets auto-increment counters |
DROP | DDL | The whole table and its structure | Data, indexes and permissions on it are gone |
In MySQL and Oracle, TRUNCATE commits implicitly and cannot be undone. SQL Server and PostgreSQL can roll it back if it runs inside an explicit transaction.
How Testers Use Each Category, and What to Watch For
- DDL appears in database migration testing. Check that new columns have the right type, length, default value and constraints, and that old data survives the change.
- DML is used daily to create test data, set records into edge-case states and verify what the application wrote to the database.
- DCL supports role-based testing. Log in as a read-only user and confirm that inserts are rejected with a proper error.
- TCL keeps experiments safe, letting you undo changes after a test.
Mistakes worth avoiding
- Running
UPDATEorDELETEwithout aWHEREclause. Run the same condition as aSELECTfirst to see which rows will change. - Mixing DDL into a transaction you plan to roll back, in a database where DDL commits automatically.
- Testing with an all-powerful admin account, which hides permission bugs that real users will hit.
- Using
TRUNCATEon a shared test environment without telling the team.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.