SQL · Chapter 8 of 42

SQL UPDATE

UPDATE modifies existing rows. ALWAYS include a WHERE clause — without one, EVERY row is updated.

`UPDATE table SET col = value WHERE condition;`

Syntax
UPDATE table SET col = value WHERE condition;

Multiple columns

`SET col1 = val1, col2 = val2, ...`

Using existing values

You can reference other columns: `UPDATE products SET price = price * 1.1;`

Example 1 (sql)
UPDATE users SET age = 26 WHERE name = 'Ana';
Output
1 row updated

Change Ana's age.

Example 2 (sql)
UPDATE products SET price = price * 1.10 WHERE category = 'Books';
Output
3 rows updated

Bump prices by 10% for one category.

Key points

  • Missing WHERE = update ALL rows.
  • SET multiple columns with commas.
  • Can reference existing column values.
  • Wrap in a transaction to allow rollback.
💡 Note: Before running an UPDATE, run the same WHERE clause as a SELECT to preview the affected rows.

📝 Quick Quiz

1. What happens without WHERE?

2. The keyword to assign new values is:

3. Best safety practice before UPDATE: