UPDATE
UPDATE
Definition
UPDATE modifies the values of existing rows in a table, without changing which rows exist. Like DELETE, its WHERE clause is what makes it targeted instead of total.
How It Works
sqlUPDATE employees SET salary = FLOOR(salary * 1.1) WHERE department = 'Engineering';
This gives every Engineering employee a 10% raise, computed from their OWN current salary — SET salary = FLOOR(salary * 1.1) reads each row's existing value before writing the new one, row by row. Multiple columns can be updated in one statement (SET salary = ..., department = ...), and every row matching the WHERE clause is updated in a single, atomic statement.
Edge Cases and Pitfalls
- Running
UPDATEwith NOWHEREclause updates EVERY row in the table — exactly the same catastrophic-by-omission risk asDELETEwith noWHERE(11.5). Always double-check theWHEREclause, or preview affected rows with an equivalentSELECTfirst. SET column = column + 1-style updates (referencing the column's own current value) are extremely common and work correctly because the RIGHT-hand side is evaluated using each row's existing value before that row'sSETtakes effect.- An
UPDATEcan fail partway through a large batch if one row's new value violates a constraint (e.g. aCHECKorUNIQUEconstraint) — likeINSERT, this rolls back the whole statement's effect by default, not just the offending row.
Key Takeaways
UPDATE table SET col = value WHERE conditionmodifies matching rows' values in place.- Omitting
WHEREupdates every row — the single most damaging accidental SQL mistake, shared withDELETE. SET col = col + exprpatterns correctly reference each row's own pre-update value.