How to update rows

Update matching rows

SET assigns new values, and WHERE chooses rows to change.

UPDATE students
SET city = 'Mombasa'
WHERE id = 1;

Change several columns

Separate assignments with commas. Expressions can use current values.

UPDATE courses
SET duration_minutes = duration_minutes + 15,
    updated_at = CURRENT_TIMESTAMP
WHERE id = 4;

Preview the target

Run a SELECT with the same WHERE first, especially before broad changes.

Avoid accidental full updates

Without WHERE, every row changes. Use a transaction for important updates and verify the affected-row count before committing.