Transactions

SQL ROLLBACK

Undo uncommitted changes in the current transaction where supported.

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

ROLLBACK [TRANSACTION];

Examples

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

BEGIN; DELETE FROM sessions WHERE user_id = 42; ROLLBACK;

SQLite-oriented variant; dialect behaviour may differ.

START TRANSACTION; DELETE FROM sessions WHERE user_id = 42; ROLLBACK;

Parameters, options and clauses

Option / clauseDescription
BEGIN / START TRANSACTIONStart a transaction; exact keywords vary by engine.
COMMITMake the transaction's changes permanent.
ROLLBACKUndo uncommitted work or return to a savepoint.
SAVEPOINTMark an intermediate point within a transaction.
Isolation levelChoose concurrency behaviour 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