Data changes

SQL DELETE

Remove matching rows from a table.

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

DELETE FROM table_name WHERE condition;

Examples

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

DELETE FROM sessions WHERE expires_at < CURRENT_TIMESTAMP;

SQLite-oriented variant; dialect behaviour may differ.

DELETE FROM sessions WHERE expires_at < CURRENT_TIMESTAMP;

Parameters, options and clauses

Option / clauseDescription
WHERELimit rows being removed; omitting it may delete every row.
USING / JOINMatch rows through another table where supported.
RETURNING / OUTPUTReturn deleted rows where supported.
LIMITLimit affected 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