CPCODELAB
SQL

UPDATE — Changing Existing Rows

7 min read

Updating Rows with UPDATE

UPDATE changes values in existing rows. The SET clause lists the columns to change and their new values. The WHERE clause restricts which rows are affected.

sql
-- Fix a single student's city
UPDATE students SET city = 'Pune' WHERE id = 2;

-- Update multiple columns at once
UPDATE students
SET city = 'Hyderabad', age = 23
WHERE email = 'aditi@example.com';

-- Apply a discount to all courses in a category
UPDATE courses
SET price = price * 0.9
WHERE category = 'Databases';

An UPDATE without a WHERE clause modifies every row in the table. Always double-check your filter before running an UPDATE in production. Run a SELECT with the same WHERE clause first to preview affected rows.

Ready to test yourself?
Practice SQL— quiz & coding exercises