ROLLBACK is a transaction control statement that reverses data modifications performed during the current transaction. If issued without options, it undoes every INSERT, UPDATE, DELETE, or DDL statement executed since the last BEGIN/START TRANSACTION or implicit transaction start. The database restores rows, indexes, and constraints to their prior state and releases any locks acquired during the rolled-back operations.You can also roll back to a specific savepoint if your database supports SAVEPOINT. In that case, only the work done after the savepoint is undone, and the transaction remains active, letting you continue processing or eventually COMMIT.ROLLBACK guarantees atomicity and consistency, two properties of ACID. It is often used in error-handling routines, long-running scripts, and applications where data integrity must be preserved if any step fails.Caveats:- ROLLBACK has no effect outside an active transaction.- Some DDL statements auto-commit in certain dialects, making them non-reversible.- Long transactions may hold locks until rollback completes, impacting concurrency.
- WORK
(TRANSACTION) - Optional synonyms for readability; no functional difference.- TO SAVEPOINT savepoint_name
- String. Name of a previously declared savepoint to which the transaction should revert.BEGIN TRANSACTION, COMMIT, SAVEPOINT, RELEASE SAVEPOINT, SET TRANSACTION
SQL-92
COMMIT makes all changes in the current transaction permanent, while ROLLBACK undoes them. Both also release locks and end the transaction.
No. Once a rollback completes, the discarded changes are gone. You must rerun the original statements if you still need them.
In auto-commit mode, every statement is implicitly committed. ROLLBACK has no effect unless you explicitly disable auto-commit or start a manual transaction.
Some databases auto-commit DDL statements or treat them as implicit commits. Check your dialect's documentation to see if ROLLBACK can reverse DDL operations.