SQL Tutorial

INSERT, UPDATE and DELETE

Create, modify and remove rows safely.

Concept

INSERT adds rows, UPDATE changes existing rows and DELETE removes rows. Always verify your WHERE condition before a destructive update or delete.

Transactions are valuable when several changes must succeed or fail together. For important data, preview affected rows with a SELECT before running a broad modification.

Example

INSERT INTO students (student_id, name, city)
VALUES (1, 'Riya', 'Jaipur');

UPDATE students
SET city = 'Ajmer'
WHERE student_id = 1;
Type the example yourself and change at least one value. Small experiments reveal syntax and behavior faster than passive reading.

Practice Tasks

  1. Insert three sample records.
  2. Update one record using its primary key.
  3. Write a delete statement that removes only one known test row.

Key Takeaways

  • DML changes stored data.
  • A missing WHERE can affect every row.
  • Use transactions for grouped changes.