CHAPTER 25
Modifying data — the right way, safely.
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');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.
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.