A safe workflow for UPDATE and DELETE
Verify scope first, modify inside a transaction, and inspect affected rows.
Problem and reasoning
The dangerous part of a data change is usually the WHERE scope, not the SET or DELETE keyword. First run SELECT with exactly the same predicate and inspect keys, sample rows, and total count. Stop if the scope is unclear.
Next, open a transaction, perform the change, and immediately inspect affected rows and critical business queries. COMMIT only when they match expectations; otherwise ROLLBACK. Do not leave a transaction open during lengthy human review.
Transactions do not replace backups. Large changes need plans for locks, log space, batching, and recovery, while application code should guard against high-risk statements without WHERE.
Examples
Sample table
orders| amount | status |
|---|---|
| 1200 | paid |
| 900 | pending |
| 1500 | paid |
| 700 | cancelled |
Before / Not recommended
UPDATE orders SET status = 'cancelled' WHERE amount < 1000;Before result
| amount | status |
|---|---|
| 1200 | paid |
| 900 | cancelled |
| 1500 | paid |
| 700 | cancelled |
After / Recommended
SELECT id, amount, status FROM orders WHERE amount < 1000 ORDER BY id;After result
| id | amount | status |
|---|---|---|
| 2 | 900 | pending |
| 4 | 700 | cancelled |
Why it is better:Run a SELECT with the same WHERE first, verify keys and scope, then execute UPDATE in a transaction and inspect affected-row count.
Was this explanation clear?
Thanks. This feedback will inform the next content review.