Learning Guides
Data Manipulation Language (DML) in SQL: INSERT, UPDATE, DELETE Explained
Quick answer: Learn SQL Data Manipulation Language commands including INSERT, UPDATE, DELETE and SELECT, with syntax, examples, and how DML differs from DDL.
What is Data Manipulation Language?
DML is the subset of SQL commands used to work with the actual data stored inside database tables, rather than the structure of the tables themselves. The main DML commands are SELECT, INSERT, UPDATE and DELETE.
INSERT: Adding New Rows
INSERT INTO students (student_id, name, email)
VALUES (101, 'Priya Sharma', 'priya@example.com');
-- Inserting multiple rows at once
INSERT INTO students (student_id, name, email)
VALUES
(102, 'Aman Verma', 'aman@example.com'),
(103, 'Neha Gupta', 'neha@example.com');
UPDATE: Modifying Existing Rows
UPDATE students
SET email = 'priya.sharma@example.com'
WHERE student_id = 101;
The WHERE clause is critical here. Without it, UPDATE modifies every single row in the table, which is one of the most common and damaging SQL mistakes.
-- DANGEROUS: updates EVERY row, since there is no WHERE clause
UPDATE students
SET email = 'default@example.com';
DELETE: Removing Rows
DELETE FROM students
WHERE student_id = 103;
Like UPDATE, omitting WHERE deletes every row in the table. Always double-check a WHERE clause, ideally by running the equivalent SELECT first to confirm which rows will be affected.
-- Safe practice: check first with SELECT
SELECT * FROM students WHERE student_id = 103;
-- Then delete once you've confirmed it's the right row
DELETE FROM students WHERE student_id = 103;
SELECT: Retrieving Data
SELECT is technically also classified as DML, since it works with data rather than structure, even though it does not modify anything.
SELECT name, email FROM students WHERE student_id = 101;
DML vs DDL
| DML | DDL |
|---|---|
| Works with data (rows) | Works with structure (tables, columns) |
| SELECT, INSERT, UPDATE, DELETE | CREATE, ALTER, DROP, TRUNCATE |
| Usually can be rolled back within a transaction | Often auto-commits immediately in many databases |
DML and Transactions
DML statements are typically used within transactions, allowing multiple changes to be committed together or rolled back entirely if something goes wrong.
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 500 WHERE account_id = 1;
UPDATE accounts SET balance = balance + 500 WHERE account_id = 2;
COMMIT; -- or ROLLBACK; if either step failed
Common Interview Questions
What is the difference between DML and DDL?
DML works with the actual data inside tables, such as inserting or updating rows. DDL works with the structure of database objects, such as creating or altering a table.
Why is it dangerous to run UPDATE or DELETE without a WHERE clause?
Without WHERE, the statement applies to every single row in the table, which can silently overwrite or destroy an entire table's data in production.
FAQ
Frequently Asked Questions
What is Data Manipulation Language in SQL?
DML is the set of SQL commands used to work with the actual data stored in tables, including SELECT, INSERT, UPDATE and DELETE.
What is the difference between DML and DDL?
DML works with the data inside tables, such as inserting or updating rows. DDL works with the structure of tables and other database objects, such as creating or dropping them.
Why should you always include a WHERE clause with UPDATE or DELETE?
Without a WHERE clause, the statement applies to every row in the table, which can unintentionally overwrite or delete an entire table's data.
Is SELECT considered a DML command?
Yes, technically, since it works with data rather than structure, even though it does not modify anything.
Keep Reading
Related Articles
Learning Guides
INNER JOIN in SQL with Examples: Complete Beginner's Guide
Learn INNER JOIN in SQL with practical examples, syntax, interview questions, and real-world use cases. A complete beginner-friendly SQL JOI
Learning Guides
OUTER JOIN in SQL: Complete Guide with Examples for Beginners
Master OUTER JOIN in SQL with practical examples and real-world scenarios. Learn LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, syntax, use cases,
Learning Guides
Multi-Row Functions in SQL: Complete Guide with Examples
Learn multi-row (aggregate) functions in SQL including SUM, AVG, COUNT, MIN, MAX, GROUP BY and HAVING, with practical examples, NULL handlin