UPDATE
updating existing rows
Overview
UPDATE changes existing rows, and WHERE controls the scope; omitting WHERE updates the whole table. A safe workflow runs SELECT with the same predicate, verifies target keys and row count, then performs UPDATE in a transaction and checks affected rows. SET may change several columns, but each value must satisfy types, constraints, and valid business-state transitions.
Basic syntax
UPDATE orders SET amount = 1300 WHERE id = 1;
Examples
UPDATE example
Change the amount of order id 1 to 1300, using the primary key to limit the update to one row.
Sample table
orders| id | amount |
|---|---|
| 1 | 1200 |
| 2 | 900 |
| 3 | 1500 |
| 4 | 700 |
Run result
| id | amount |
|---|---|
| 1 | 1300 |
| 2 | 900 |
| 3 | 1500 |
| 4 | 700 |
Common issues
Checking the same WHERE predicate reveals an overly broad or missing condition before rows are changed.
UPDATE changes every row and DELETE removes every row, so verify scope before production use.
Use a transaction, inspect affected rows, commit only after verification, and keep recoverable backups for critical data.
Tags
Was this explanation clear?
Thanks. This feedback will inform the next content review.