Part 44: Updating Rows with UPDATE & The Danger of Missing WHERE
The UPDATE statement modifies values in existing rows.
1. Syntax
UPDATE employees
SET salary = salary * 1.05,
updated_at = CURRENT_TIMESTAMP
WHERE department = 'Engineering';
2. ⚠️ The Production Nightmare: Missing WHERE
If you execute UPDATE employees SET salary = 100000; without a WHERE clause, every single row in the company receives that salary!
Safety Rule: In database clients like DBeaver or MySQL Workbench, enable "Safe Update Mode" to block queries that omit a WHERE clause.
Key Takeaways
- Always verify your
WHEREcondition before runningUPDATE. - Test conditions first using a
SELECTwith the identicalWHEREclause.
In Part 45, we explore Updating with Joins across Multiple Tables!

