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.
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.
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.