| Lesson 11 | A warning about UPDATE |
| Objective | Use caution when using the SQL UPDATE statement. |
The UPDATE statement is powerful because it changes stored data. That same power makes it risky:
if you omit the WHERE clause, you can update every row in the table.
For example, suppose you intended to update only a few customers. If you accidentally run an update without a filter, you could overwrite an entire column and destroy data integrity.
The safest mindset is: every UPDATE is a data migration—treat it as an intentional, verified change.
In standard SQL, UPDATE includes a required UPDATE clause and SET clause,
and an optional WHERE clause.
UPDATE <table name>
SET <set clause expression>
[{, <set clause expression>} ...]
[WHERE <search condition>];
The WHERE clause is “optional” in syntax terms, but in production work it is usually
mandatory in practice unless you explicitly intend to update every row.
Before updating, run a SELECT using the same WHERE clause to confirm you are targeting
the correct rows.
Your SQL tool will usually report “N rows updated.” If you expected 3 rows and you see 30,000, stop immediately.
In most databases, an UPDATE can be rolled back until you commit. Avoid autocommit when doing
risky changes, and commit only after you have validated results.
Practice updates in a development/test database or on a backup copy of the table before running them against live data.
For critical tables, ensure you have recent backups, flashback/time-travel capabilities (if supported), or an audit trail. This is how you recover if a bad update is committed.
This statement updates every row because it has no WHERE clause:
UPDATE customers
SET city = 'Seattle';
If you intended to update only customers in Washington, the correct version would include a filter:
UPDATE customers
SET city = 'Seattle'
WHERE state = 'WA';
The most common update failure is not syntax—it is scope. Always verify the WHERE clause, validate the target
rows first, and commit only after confirming the change matches your intent.
The next lesson builds on this foundation with more advanced update techniques.