ROLLBACK
ROLLBACK returns the database to the state it was in before the current transaction began. This statement releases the locks acquired since the last SAVEPOINT or START TRANSACTION.
The ROLLBACK TO SAVEPOINT statement rolls back the transaction to the specified savepoint.
Syntax
ROLLBACK [
WORK ] [
TO
SAVEPOINT savepoint-name ]
Remarks
ROLLBACK, SAVEPOINT, and RELEASE are supported at the session level (outside of stored procedures) only if AUTOCOMMIT is off. Otherwise, ROLLBACK, SAVEPOINT, and RELEASE must be used within a stored procedure.
Any committed statements within a stored procedure are controlled by the outermost transaction of the calling SQL application.
In the case of nested transactions, ROLLBACK rolls back to the nearest START TRANSACTION. For example, if transactions are nested five levels, then five ROLLBACK statements are needed to undo all of the transactions. A transaction is either committed or rolled back, but not both. That is, you cannot roll back a committed transaction.
Examples
The following statement undoes the changes made to the database since the beginning of a transaction.
ROLLBACK WORK;
The following statement undoes the changes made to the database since the last savepoint, named Svpt1.
ROLLBACK TO SAVEPOINT Svpt1;
See Also