DML Notes
DML Notes
What is DML?
- DML stands for Data Manipulation Language.
- It is a subset of SQL (Structured Query Language).
- DML commands are used to manage and manipulate data stored in database tables.
- It allows users to perform operations like inserting, updating, deleting, and retrieving data.
1. INSERT
- Used to add new records (rows) into a table.
Syntax:
INSERT INTO table_name (column1, column2, ...)
VALUES (value1, value2, ...);
2. UPDATE
- Used to modify existing records in a table.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Note: Use WHERE clause carefully, otherwise all rows will be updated.
3. DELETE
- Used to remove records from a table.
Syntax:
DELETE FROM table_name
WHERE condition;
Characteristics of DML:
- DML operations are temporary unless committed.
- DML commands are used by end-users and developers for day-to-day data management.
- DML operations can be controlled using:
- COMMIT -> Save changes permanently.
- ROLLBACK -> Undo changes.
- SAVEPOINT -> Create intermediate checkpoints.
Example:
-- Insert new record
INSERT INTO students (id, name, grade) VALUES (1, 'John', 'A');
-- Update record
UPDATE students SET grade = 'B' WHERE id = 1;
-- Delete record
DELETE FROM students WHERE id = 1;
-- Select data
SELECT * FROM students;