SQL FOUNDATIONS:Data Manipulation (INSERT, UPDATE, DELETE)

Learn INSERT, UPDATE, and DELETE with safe preview exercises.

SQL Data Manipulation (INSERT, UPDATE, DELETE) Explained with Examples + Practice Questions

When to Use Data Manipulation

  • Use INSERT to add new data
  • Use UPDATE to modify existing data
  • Use DELETE to remove data

These operations are used in:

  • Backend systems
  • Database management
  • Real-world applications

Example Dataset

Table: employees

idnamedepartmentsalary
1JohnHR40000
2AliceIT60000
3BobIT55000

INSERT (Add Data)

Insert a New Row

sql
INSERT INTO employees (id, name, department, salary)
VALUES (4, 'Emma', 'Finance', 70000);

Insert Multiple Rows

sql
INSERT INTO employees (id, name, department, salary)
VALUES
(5, 'David', 'HR', 45000),
(6, 'Ankit', 'IT', 52000);

Key Points:

  • Must match column order
  • Required columns cannot be NULL
  • Always specify column names (best practice)

UPDATE (Modify Data)

Update Specific Row

sql
UPDATE employees
SET salary = 65000
WHERE name = 'Alice';

Update Multiple Columns

sql
UPDATE employees
SET department = 'Finance', salary = 70000
WHERE id = 3;

Key Points:

  • Always use WHERE
  • Without WHERE, all rows will be updated

DELETE (Remove Data)

Delete Specific Row

sql
DELETE FROM employees
WHERE id = 2;

Delete Multiple Rows

sql
DELETE FROM employees
WHERE department = 'HR';

Key Points:

  • Always use WHERE
  • Without WHERE, deletes all rows

INSERT vs UPDATE vs DELETE

OperationPurpose
INSERTAdd new rows
UPDATEModify existing rows
DELETERemove rows

Combining with Conditions

sql
UPDATE employees
SET salary = salary + 5000
WHERE department = 'IT';

Key Concepts

  • INSERT adds data
  • UPDATE modifies data
  • DELETE removes data
  • WHERE is critical to avoid mistakes

Practice Note

For safety, these exercises preview the effect using SELECT queries. When write actions are enabled later, you can swap them to real INSERT/UPDATE/DELETE.

Data Manipulation (INSERT, UPDATE, DELETE) Missions

Solve exercises in sequence to unlock the next mission.

1

Preview insert Ravi

Insert a new employee: (7, 'Ravi', 'IT', 58000).

Solve Mission
2

Preview insert Neha + Karan

Insert two employees: (8, 'Neha', 'HR', 42000) and (9, 'Karan', 'Finance', 72000).

Locked
3

Preview update Bob salary

Update salary of employee 'Bob' to 60000.

Locked
4

Preview update department

Update department of employee with id = 1 to 'Finance'.

Locked
5

Preview raise IT salaries

Increase salary of all IT employees by 5000.

Locked
6

Preview delete id 3

Delete employee with id = 3.

Locked
7

Preview delete HR

Delete all employees from HR department.

Locked
8

Preview set NULL salaries to 0

Update salary to 0 where salary is NULL.

Locked
9

Preview insert name + department

Insert employee with only name and department (salary default).

Locked
10

Preview 10 percent raise

Increase salary by 10% for employees earning less than 50000.

Locked