DML Commands in SQL Explained: INSERT, UPDATE, DELETE Drills
DML commands in SQL are INSERT, UPDATE, and DELETE, and they change data inside tables. This post walks you through DDL, DML, DCL, and TCL with runnable examples and interview-ready drills.
Most tutorials call SELECT a DML command, but in the official classification it isn't. That one mistake costs freshers points in interviews. Here is the exact answer and how to remember it.
The examples below use a simple employees table, and you can copy them into any SQL editor to follow along. For extra practice, try adding your own rows, updating multiple columns at once, and deleting with different WHERE conditions.
- DML commands in SQL are INSERT, UPDATE and DELETE, and they change the data inside tables.
- SELECT is technically a DQL command, not DML.
- DDL commands like CREATE and ALTER change the table structure.
- DCL commands like GRANT control permissions.
- TCL commands like COMMIT and ROLLBACK manage transactions.
Which are the four command groups at a glance?
SQL commands split into DDL, DML, DCL and TCL, and each group does one job (GeeksforGeeks): DDL changes the structure, DML changes the data, DCL changes permissions, and TCL controls transactions. | Group | Commands | What they do | |---|---|---| | DDL | CREATE, ALTER, DROP, TRUNCATE | Change table structure | | DML | INSERT, UPDATE, DELETE | Change data inside tables | | DCL | GRANT, REVOKE | Control user permissions | | TCL | COMMIT, ROLLBACK, SAVEPOINT | Manage transactions | The line between DML and DDL confuses most beginners. DDL builds the container; DML fills it. You cannot INSERT a row into a table that does not exist yet, so DDL always comes first.How do DDL commands shape the table itself?
DDL commands like CREATE, ALTER, DROP and TRUNCATE create or change the schema, the structure that holds the data (GeeksforGeeks). Here is a runnable example that creates an employees table, adds a column, and then drops the table:-- Create a new table
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
department VARCHAR(50)
);
-- Add a column to the existing table
ALTER TABLE employees ADD salary DECIMAL(10, 2);
-- Remove the entire table
DROP TABLE employees;
TRUNCATE deserves a special note: it removes all rows but keeps the table structure. DELETE (which we cover next) removes rows one by one and can be rolled back. That difference matters in interviews.
How do DML commands change the data inside tables?
DML commands are INSERT, UPDATE and DELETE, and they add, change or remove rows in a table (GeeksforGeeks). This is the core every interviewer expects you to know cold. Here is the full drill, in the order you would run it:-- INSERT adds rows
INSERT INTO employees (first_name, last_name, department)
VALUES ('Jane', 'Smith', 'HR');
INSERT INTO employees (first_name, last_name, department)
VALUES ('Rahul', 'Sharma', 'Engineering');
INSERT INTO employees (first_name, last_name, department)
VALUES ('Maria', 'Garcia', 'Finance');
-- UPDATE changes existing rows
UPDATE employees
SET department = 'Engineering'
WHERE first_name = 'Jane';
-- DELETE removes rows
DELETE FROM employees
WHERE first_name = 'Maria';
Notice the WHERE clause in UPDATE and DELETE. Skip it and you change or remove every row in the table. Forgetting WHERE updates every row in the table. In a production database, that can corrupt a thousand records and take the team hours to fix. Interviewers ask this exact question because it happens.
The distinction between the DML trio matters for the interview. Each command does one job. INSERT adds a new row. UPDATE changes values in existing rows. DELETE removes rows entirely. There is no fourth DML command to memorize.
Is SELECT DQL or DML?
SELECT is the only DQL command, and its clauses like WHERE and ORDER BY are part of SELECT, not separate commands (GeeksforGeeks). This is the most common confusion in SQL. Many tutorials list SELECT under DML because it reads data. But the official classification keeps DML for commands that change data. SELECT only reads it.-- SELECT reads data; WHERE and ORDER BY are clauses of SELECT
SELECT first_name, department
FROM employees
WHERE department = 'Engineering'
ORDER BY first_name;
FROM, WHERE, GROUP BY, HAVING, ORDER BY, DISTINCT and LIMIT are all clauses that belong to SELECT. They are not standalone commands. When an interviewer asks "which commands are DML?", the answer is INSERT, UPDATE, DELETE. SELECT is its own category.
Which commands control who gets access?
DCL has only GRANT and REVOKE, and they give or take away user permissions on database objects (K21 Academy).-- Give a user permission to read and update the employees table
GRANT SELECT, UPDATE ON employees TO user_name;
-- Take away the update permission
REVOKE UPDATE ON employees FROM user_name;
You will rarely write DCL commands as a fresher, but you need to recognize them in a multiple-choice question. GRANT adds a permission. REVOKE removes one. The pair shows up in almost every SQL fundamentals round.
How do TCL commands make changes permanent or undo them?
TCL commands COMMIT, ROLLBACK and SAVEPOINT manage transactions, and they only respond to DML statements like INSERT, UPDATE and DELETE (GeeksforGeeks). Here is the full runnable sequence:BEGIN TRANSACTION;
INSERT INTO employees (first_name, last_name, department)
VALUES ('David', 'Lee', 'Engineering');
SAVEPOINT before_update;
UPDATE employees
SET department = 'Finance'
WHERE first_name = 'David';
-- Undo just the UPDATE, keep the INSERT
ROLLBACK TO SAVEPOINT before_update;
-- Make the INSERT permanent
COMMIT;
This syntax works in PostgreSQL and MySQL. In SQL Server, use BEGIN TRANSACTION; and SAVE TRANSACTION; instead.
COMMIT makes changes permanent and irreversible. ROLLBACK restores everything to the last committed state. SAVEPOINT creates a logical rollback point so you can undo part of a transaction without losing all of it. TCL only responds to DML statements. Run a DDL command like CREATE inside a transaction and it is not covered by ROLLBACK the same way. In most databases, DDL commands cause an implicit commit, so the transaction ends before you can roll back. The behavior varies by database, so test it in your own editor.What common mistakes do freshers make in SQL rounds?
The most common mistakes are calling SELECT a DML command, forgetting COMMIT after UPDATE, and using DELETE when TRUNCATE fits (K21 Academy).Do
- Use TRUNCATE to clear all rows fast.
- Use WHERE with UPDATE and DELETE.
- Wrap multi-step changes in a transaction.
Don't
- Don't call SELECT a DML command.
- Don't forget COMMIT in a transaction.
- Don't use DELETE to clear a whole table.
For a video walkthrough, watch Lec-60: All Types of SQL Commands with Example | DDL, DML, DCL, TCL and CONSTRAINTS | DBMS — Gate Smashers (YouTube).
