UPDATE

The SQL statement that changes values in existing rows, choosing the rows with WHERE and the new values with SET.

An UPDATE without a WHERE clause rewrites every row in the table.

In more detail

Without a WHERE clause it changes every row in the table. Preview the target rows with a SELECT using the same predicate, then check the affected row count. SET stock = stock - 1 computes the new value inside the database, which avoids overwriting a concurrent change with a stale one.

Example

UPDATE products SET stock = stock + 10 WHERE id = 5;

Related terms

Taught in

References