UPDATE modifies existing rows in a table.
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;
Example
UPDATE employees
SET salary = 75000
WHERE name = 'Karan';
Only Karan's row changes. Every other row is untouched.
Updating Multiple Columns
UPDATE employees
SET department = 'Senior Engineering', salary = salary * 1.10
WHERE department = 'Engineering' AND salary > 60000;
Note salary = salary * 1.10 — you can reference the column's current value inside its own update.
The One Rule That Matters Most: Never Forget WHERE
-- DANGEROUS: updates every single row in the table
UPDATE employees
SET salary = 75000;
Without a WHERE clause, UPDATE applies to every row. This is the single most common — and most damaging — SQL mistake in real production systems. Always write and double-check your WHERE clause before running an UPDATE, especially outside a transaction.
Safer Habit: Check with SELECT First
-- Step 1: confirm exactly which rows will be affected
SELECT * FROM employees WHERE department = 'Engineering' AND salary > 60000;
-- Step 2: only then run the UPDATE with the same WHERE clause
Dialect Note: UPDATE with a JOIN
-- MySQL
UPDATE orders o
JOIN customers c ON o.customer_id = c.id
SET o.customer_tier = c.tier
WHERE c.tier = 'gold';
-- PostgreSQL (different syntax — uses FROM)
UPDATE orders o
SET customer_tier = c.tier
FROM customers c
WHERE o.customer_id = c.id AND c.tier = 'gold';
Common Mistakes
- Running
UPDATEwithoutWHERE(see above) - Updating a column used inside the same
WHEREclause and getting unexpected results depending on evaluation order - Not wrapping risky updates in a transaction so a mistake can be rolled back (see Transactions)
Interview Relevance
Expect scenario questions like "give every employee in Sales a 10% raise" — testing whether you remember the WHERE clause and correct arithmetic on the existing column value.
Practice Question
Write a statement to increase the price of all products in the "Electronics" category by 5%.