DataBolt

SQL LEARNING PLATFORM

23

CHAPTER 23

INSERT, UPDATE, DELETE

Modifying data — the right way, safely.

6

Learning Blocks

SQL

Interactive Queries

In This Chapter

Concepts you'll master

1

adding single and multiple rows

2

UPDATE — modifying existing data with WHERE

3

DELETE — removing rows safely

4

The golden rule: always test with SELECT first

21.1 - INSERT

SQL
SQL QUERY
INSERT INTO employees (name, department, salary, hire_date)
VALUES ('Nisha', 'IT', 71000, '2024-03-01');
-- Multiple rows at once
INSERT INTO employees (name, department, salary, hire_date) VALUES
    ('Akash', 'Sales', 58000, '2024-04-01'),
    ('Pooja', 'HR', 62000, '2024-04-15');

21.2 - UPDATE

10% raise for all IT employees
SQL QUERY
UPDATE employees
SET salary = salary * 1.10
WHERE department = 'IT';

💡 Watch Out: Always include a WHERE clause in UPDATE. 'UPDATE employees SET salary = salary * 1.10' with no WHERE gives everyone a raise — not just IT. This is called a 'fat finger' mistake and it has caused real production incidents at major companies.

21.3 - DELETE

SQL
SQL QUERY
-- Safe workflow: SELECT first, then DELETE
SELECT * FROM employees WHERE salary < 50000;        -- verify what
will be deleted
DELETE FROM employees WHERE salary < 50000;          -- then delete

Pro Tips: Wrap destructive operations in a transaction: START TRANSACTION; DELETE ...; ROLLBACK; — verify, then COMMIT when satisfied. This is standard practice at any serious engineering team.

Exercise

Practice your SQL skills

SQL EDITOR
Press semicolon (;) to auto-run query

Tasks

Complete all SQL challenges

1

Insert a new employee Rohit into the table.

Current Task
2

Update Priya's salary to 80000.

3

Change Rahul's department to Marketing.

4

Delete the employee with emp_id 8.

5

Insert a new employee Neha using column names.

6

Delete all employees from HR department.

Need help solving this task?