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.

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');

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;

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;

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

Practice Questions

  1. What is DML?
  2. Write syntax for INSERT command.
  3. Why WHERE clause is important in UPDATE?
  4. Differentiate DELETE and TRUNCATE.
  5. 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