Data changes

SQL UPDATE

Change values in existing rows.

Availability: Common SQL with references for SQL standard, MySQL/MariaDB, PostgreSQL, SQL Server, SQLite and Oracle Database; syntax and feature support vary by engine and version.中文

Syntax

UPDATE table_name SET column = value [, column = value] WHERE condition;

Examples

Example (standard-style syntax). Verify supported keywords in your database.

UPDATE users SET active = FALSE WHERE last_login < DATE '2024-01-01';

SQLite-oriented variant; dialect behaviour may differ.

UPDATE users SET active = 0 WHERE last_login < '2024-01-01';

Parameters, options and clauses

Option / clauseDescription
SETAssign values to one or more columns.
WHERELimit rows being changed; omitting it may update every row.
FROM / JOINUse other tables in the update where the dialect supports it.
RETURNING / OUTPUTReturn updated rows where supported.

Dialect references

Safety note

Review a command and its target before running it. Commands that alter files, services, accounts, disks, permissions or databases may be difficult to reverse. Test in a safe environment and keep backups.

Official reference ↗Back to directory