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 a self-increment/decrement expression of the formcol = col +|- <integer literal or ?>(integer andNUMERICcolumns only; the left operand must be the assigned column itself).Predicates in the
WHEREclause are combined withANDonly and must be equality predicates covering the complete primary key (one equality per primary-key column); non-key predicates and range predicates are not supported.Primary-key columns cannot be updated.
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 (self-increment):
UPDATE stock
SET s_quantity = s_quantity + 5
WHERE s_w_id = 1 AND s_i_id = 10;
Update with a placeholder:
UPDATE stock
SET s_quantity = ?
WHERE s_w_id = ? AND s_i_id = ?;