DataBolt

All Lessons

Introduction to SQL
SQL Lesson 1: Your Sample Database
SQL Lesson 2: SELECT — Reading data
SQL Lesson 3: WHERE — Filtering rows
SQL Lesson 4: AND, OR, NOT
SQL Lesson 5: BETWEEN, IN, LIKE
SQL Lesson 6: NULL — The Mystery Value
SQL Lesson 7: ORDER BY
SQL Lesson 8: LIMIT & OFFSET
SQL Lesson 9: Aggregate Functions
SQL Lesson 10: GROUP BY
SQL Lesson 11: HAVING
SQL Lesson 12: INNER JOINs
SQL Lesson 13: LEFT JOINs
SQL Lesson 14: RIGHT JOINs
SQL Lesson 15: SELF JOINs
SQL Lesson 16: UNION JOINs
SQL Lesson 17: Joining Multiple Tables
SQL Lesson 18: Subqueries
SQL Lesson 19: CTEs (WITH)
SQL Lesson 20: CASE Statements
SQL Lesson 21: Window Functions
SQL Lesson 22: String Functions
SQL Lesson 23: Date & Time Functions
SQL Lesson 24: INSERT, UPDATE, DELETE
SQL Lesson 25: CREATE TABLE & DDL
SQL Lesson 26: Indexes & Performance
SQL Lesson 27: Transactions & ACID
SQL Lesson 28: SQL Execution Order
SQL Lesson 29: 50 Practice Problems

CHAPTER 25

INSERT, UPDATE, DELETE

Modifying data — the right way, safely.

IN THIS CHAPTER

  • adding single and multiple rows
  • UPDATE — modifying existing data with WHERE
  • DELETE — removing rows safely
  • The golden rule: always test with SELECT first

21.1 - INSERT

SQL

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

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

-- 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 👇

Exercise:

Tasks

1.👉Insert a new employee Rohit into the table.
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.
Stuck? Read this task's