SQL Keywords

SQL UPDATE

What is the SQL UPDATE statement?

Modifies existing rows in a table by setting new column values.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL UPDATE:

SQL UPDATE Full Explanation

UPDATE changes data that already exists in a table. You specify the target table, list one or more columns to set, and optionally filter which rows are affected with a WHERE clause. Without a WHERE clause, every row in the table is updated, so use it carefully. Most dialects support joins in an UPDATE or allow a subquery in the SET list. Some engines also return the modified rows via RETURNING. UPDATE runs inside a transaction, so it can be rolled back if an error occurs or if you call ROLLBACK. Concurrency controls such as row-level locks ensure data integrity while the statement executes.

SQL UPDATE Syntax

UPDATE [ONLY] table_name
SET column1 = value1 [, column2 = value2 ...]
[FROM other_table ...]          -- dialect-specific
[WHERE condition]
[RETURNING * | column_list];

SQL UPDATE Parameters

  • table_name (identifier) - Target table to modify
  • column (identifier) - One or more columns to update
  • value (expression) - New value or expression to assign
  • condition (boolean) - Filters rows to update (optional)
  • ONLY (keyword) - In PostgreSQL, skip child tables (optional)
  • FROM (clause) - Join additional tables for reference (dialect specific)
  • RETURNING (clause) - Return modified rows (PostgreSQL, SQLite, etc.)

Example Queries Using SQL UPDATE

-- Give a 5 percent raise to Engineering employees
UPDATE employees
SET salary = salary * 1.05
WHERE department = 'Engineering';

-- Update with a subquery
UPDATE orders
SET status = 'shipped'
WHERE id IN (SELECT order_id FROM shipments);

-- Join in UPDATE (PostgreSQL)
UPDATE sales s
SET region = r.new_region
FROM region_map r
WHERE s.region = r.old_region;

-- Return changed rows (PostgreSQL)
UPDATE users
SET last_login = NOW()
WHERE id = 42
RETURNING id, last_login;

Expected Output Using SQL UPDATE

  • The specified rows are modified in place
  • The database returns the number of affected rows, and with RETURNING it also returns the updated data set

Use Cases with SQL UPDATE

  • Correct data entry errors without re-inserting rows
  • Apply bulk price changes or salary increases
  • Timestamp a row on user activity
  • Migrate data during schema changes
  • Toggle feature flags or status columns in deployments

Common Mistakes with SQL UPDATE

  • Omitting WHERE and unintentionally updating every row
  • Forgetting to wrap multi-table UPDATEs in a transaction
  • Misordering columns when using positional UPDATE in MySQL
  • Using non-deterministic subqueries that return multiple rows
  • Expecting RETURNING in dialects that do not support it

Related Topics

First Introduced In

SQL-86 (SQL-1)

Frequently Asked Questions

How do I update every row in a table?

Omit the WHERE clause entirely: `UPDATE table_name SET column = value;` Be sure this is intentional because the change cannot be scoped later.

Can I update from another table?

Yes in many dialects. PostgreSQL uses `FROM`, SQL Server uses `JOIN` syntax inside UPDATE, and MySQL supports multi-table UPDATE.

How do I avoid accidental mass updates?

Always include a WHERE clause or run inside a transaction and check the affected row count before COMMIT.

Does UPDATE lock the entire table?

Most engines place row-level locks on the affected rows, not the full table, unless an index is missing or the optimizer escalates the lock.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!