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
| Database System | Support Status | Since Version | Notes |
|---|---|---|---|
| MySQL | Native | all | Standard |
| PostgreSQL | Native | all | Standard |
| SQL Server | Native | all | Standard + OUTPUT |
| Oracle | Native | all | Standard + RETURNING |
| SQLite | Native | all | Standard |
Details
Basic DML for modifying rows.
Standard Syntax
UPDATE table_name
SET col1 = v1, col2 = v2
WHERE condition;
Version Support
MySQL: Native in all listed versions
PostgreSQL: Native in all listed versions
SQL Server: Native in all listed versions
Oracle: Native in all listed versions
SQLite: Native in all listed versions
Per-Database Syntax & Notes
MySQL Native syntax
Standard
UPDATE tbl SET c1=v1 WHERE …;
PostgreSQL Native syntax
Standard
UPDATE tbl SET c1=v1 WHERE … RETURNING *;
SQL Server Native syntax
Standard + OUTPUT
UPDATE tbl
SET c1=v1
OUTPUT inserted.*
WHERE …;
Oracle Native syntax
Standard + RETURNING
UPDATE tbl SET c1=v1 WHERE … RETURNING * INTO …;
SQLite Native syntax
Standard
UPDATE tbl SET c1=v1 WHERE …;