Modify existing rows in a table.

Modifies existing rows in a table, optionally filtering with a WHERE clause. Without WHERE, all rows are updated -- often a mistake. SET clauses are evaluated left-to-right, which matters for interdependent column updates.

Compatibility

Show:
Database System Support Status Since Version Notes
MySQL ✓ Supported all Standard
PostgreSQL ✓ Supported all Standard
SQL Server ✓ Supported all Standard + OUTPUT
Oracle ✓ Supported all Standard + RETURNING
SQLite ✓ Supported all Standard

Details

Basic DML for modifying rows.

Standard Syntax

UPDATE table_name SET col1 = v1, col2 = v2 WHERE condition;

Version Support

MySQL: Since all PostgreSQL: Since all SQL Server: Since all Oracle: Since all SQLite: Since all

Per-Database Syntax & Notes

MySQL

Standard

UPDATE tbl SET c1=v1 WHERE …;

PostgreSQL

Standard

UPDATE tbl SET c1=v1 WHERE … RETURNING *;

SQL Server

Standard + OUTPUT

UPDATE tbl SET c1=v1 OUTPUT inserted.* WHERE …;

Oracle

Standard + RETURNING

UPDATE tbl SET c1=v1 WHERE … RETURNING * INTO …;

SQLite

Standard

UPDATE tbl SET c1=v1 WHERE …;