๐Ÿ“˜ What is DML (Data Manipulation Language)?

DML (Data Manipulation Language) is the part of SQL used to interact with the actual data stored in tables โ€” reading, inserting, updating, and deleting records.

If the database structure (tables, columns) is a house built using DDL, then DML is how you live in it โ€” putting stuff in, changing things around, or throwing stuff out.


๐Ÿ”ง Key DML Commands:

CommandWhat It Does
SELECTRetrieves data from one or more tables
INSERTAdds new rows to a table
UPDATEModifies existing rows in a table
DELETERemoves rows from a table

๐Ÿ› ๏ธ Example Usage:

1. INSERT

INSERT INTO users (id, name, email)
VALUES (1, 'Gaurav', 'gaurav@example.com');

Adds a new row to the users table.


2. SELECT

SELECT name, email FROM users WHERE id = 1;

Fetches specific data from the table.


3. UPDATE

UPDATE users SET email = 'new@email.com' WHERE id = 1;

Changes the email of the user with ID 1.


4. DELETE

DELETE FROM users WHERE id = 1;

Deletes the user with ID 1 from the table.


๐Ÿงช DML + Transactions:

DML operations can be rolled back using TCL (Transaction Control Language):

BEGIN;
DELETE FROM users WHERE id = 1;
ROLLBACK; -- undoes the delete

So, DML changes are not permanent until committed.


โš ๏ธ DML vs DDL:

FeatureDDLDML
AffectsStructure (schema)Data (rows/records)
Auto-commitYesNo (can rollback)
ExampleCREATE TABLEINSERT INTO table

๐Ÿง  Interview Line:

โ€œDML allows users to interact with data using SELECT, INSERT, UPDATE, and DELETE. Unlike DDL, DML operations are transactional and can be committed or rolled back.โ€