UPDATE
UPDATE changes existing data in a table. It is one of the four core data-manipulation statements alongside SELECT, INSERT, and DELETE — and, together with DELETE, one of the two that can silently affect far more rows than you intended if you are not careful.
Basic syntax
UPDATE syntax
UPDATE table_name
SET column1 = value1,
column2 = value2
WHERE condition;For example, to give a single employee a new salary:
Updating one row
UPDATE employees SET salary = 95000 WHERE id = 42;
Updating multiple columns at once
Separate each column assignment with a comma inside the same SET clause — there is no need to run separate statements:
Updating several columns together
UPDATE employees
SET salary = 95000,
department = 'Platform Engineering',
updated_at = NOW()
WHERE id = 42;Updating many rows with a condition
The WHERE clause works exactly like it does in SELECT — it can match many rows, not just one:
Giving everyone in a department a raise
UPDATE employees SET salary = salary * 1.05 WHERE department = 'Engineering';
salary * 1.05 reads the row’s current value as part of computing its new value — this is a very common and useful pattern for percentage adjustments, counters, and running totals.Dangerous — no WHERE clause
-- This gives EVERY employee in the entire table a 5% raise UPDATE employees SET salary = salary * 1.05;
Verify first, then update
-- Step 1: check exactly which rows match SELECT id, department, salary FROM employees WHERE department = 'Engineering'; -- Step 2: once the row count and rows look right, run the update UPDATE employees SET salary = salary * 1.05 WHERE department = 'Engineering';
UPDATE with a join
You often need to update a table based on values from another table. The syntax for this differs by database:
PostgreSQL — UPDATE ... FROM
UPDATE orders o SET status = 'archived' FROM customers c WHERE o.customer_id = c.id AND c.is_deleted = TRUE;
MySQL / SQL Server — UPDATE ... JOIN
UPDATE orders o JOIN customers c ON o.customer_id = c.id SET o.status = 'archived' WHERE c.is_deleted = TRUE;
A missing or overly broad WHERE clause is the single most common cause of accidental mass data changes
Wrapping UPDATE statements in an explicit transaction lets you review the result and roll back if something looks wrong (covered in the transactions section)
Some teams require a WHERE clause on every UPDATE and DELETE via tooling or code review — a reasonable safeguard for production databases