Update#
Syntax#
UPDATE table_name
SET column_name = expression [, column_name = expression ...]
WHERE predicate [AND predicate ...];
Rules#
WHEREis required. AnUPDATEwithout aWHEREclause is rejected by the parser.The right-hand side of an assignment can be a literal, a placeholder, or an arithmetic expression involving other columns and literals.
Predicates in the
WHEREclause are combined withANDonly.
Examples#
Simple update with a literal:
UPDATE stock
SET s_quantity = 100
WHERE s_w_id = 1 AND s_i_id = 10;
Update using an arithmetic expression:
UPDATE users
SET total = count + 1, balance = balance - amount
WHERE id = 1;
Update with a placeholder:
UPDATE stock
SET s_quantity = ?
WHERE s_w_id = ? AND s_i_id = ?;