SQLUPDATE

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

SQL
UPDATE table_name
SET column1 = value1,
    column2 = value2
WHERE condition;

For example, to give a single employee a new salary:

Updating one row

SQL
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

SQL
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

SQL
UPDATE employees
SET salary = salary * 1.05
WHERE department = 'Engineering';
Notice that 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.
Forgetting WHERE updates every single row
If you omit the WHERE clause entirely, the UPDATE applies to every row in the table, with no confirmation prompt:

Dangerous — no WHERE clause

SQL
-- This gives EVERY employee in the entire table a 5% raise
UPDATE employees
SET salary = salary * 1.05;
Tip
Before running an UPDATE with a non-trivial WHERE clause, run the equivalent SELECT first, using the exact same condition, to see precisely which rows will be affected:

Verify first, then update

SQL
-- 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

SQL
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

SQL
UPDATE orders o
JOIN customers c ON o.customer_id = c.id
SET o.status = 'archived'
WHERE c.is_deleted = TRUE;
Always check row counts
Most database clients report how many rows an UPDATE affected. Get in the habit of glancing at that number — if you expected to change 12 rows and the client reports 12,000, stop and investigate before doing anything else.
  • 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