Insert, Update & Delete Records
INSERT, UPDATE, and DELETE are SQL commands used to manipulate
data stored inside database tables.
They come under DML (Data Manipulation Language).
1. What is DML?
DML (Data Manipulation Language) is used to retrieve, store, modify, and delete data in database tables.
- Works on table data
- Does not change table structure
- Common DML commands: INSERT, UPDATE, DELETE
2. INSERT INTO
The INSERT INTO command is used to add new records (rows) into a table.
2.1 Insert All Columns
INSERT INTO student VALUES (101, 'Amit', 78);
2.2 Insert Specific Columns
INSERT INTO student (RollNo, Name) VALUES (102, 'Riya');
- Order of values must match column order
- NULL allowed if column permits
3. Insert Multiple Records
INSERT INTO student (RollNo, Name, Marks) VALUES (103, 'Suman', 72), (104, 'Neha', 85), (105, 'Rahul', 90);
4. UPDATE
The UPDATE command modifies existing records in a table.
4.1 Update All Rows
UPDATE student SET Marks = 80;
4.2 Update Specific Rows (Using WHERE)
UPDATE student SET Marks = 88 WHERE RollNo = 102;
- WHERE clause is important
- Without WHERE, all rows are updated
5. DELETE
The DELETE command removes records from a table.
5.1 Delete All Records
DELETE FROM student;
5.2 Delete Specific Records
DELETE FROM student WHERE RollNo = 105;
- Deletes rows, not table structure
- Can be rolled back (if transaction supported)
6. DELETE vs TRUNCATE
DELETE TRUNCATE ---------------------------- --------------------------- DML command DDL command Deletes selected rows Deletes all rows WHERE clause allowed WHERE not allowed Can be rolled back Cannot be rolled back
7. Important Safety Tips
- Always use WHERE with UPDATE and DELETE
- Check records using SELECT before DELETE
- Take backup before mass update/delete
Practice Questions
- What is DML?
- Write syntax for INSERT command.
- Why WHERE clause is important in UPDATE?
- Differentiate DELETE and TRUNCATE.
- How to insert multiple records?
Practice Task
Write SQL commands to:
✔ Insert 3 student records
✔ Update marks of one student
✔ Delete a student record
✔ Remove all records from table safely