×
☰ See All Chapters

MySQL ROLLBACK

The ROLLBACK command is the transactional control command that discards all the transactions since the last COMMIT or ROLLBACK command that have not already been saved to the database. If anything went wrong in your query execution, ROLLBACK in used to revert the changes.

The syntax for the ROLLBACK command is as follows:

ROLLBACK [ WORK ] [ TO [SAVEPOINT] savepoint_name  | FORCE 'string' ];

Once again, as in the COMMIT statement, the WORK keyword is an optional part of the ROLLBACK syntax.

Parameters or Arguments

WORK: This is Optional. Issuing the ROLLBACK with or without the WORK parameter will result in the same outcome.

TO SAVEPOINT savepoint_name: This is Optional. The ROLLBACK statement undoes all changes for the current session up to the savepoint specified by savepoint_name. If this clause is omitted, then all changes are undone.

FORCE 'string': This is Optional. It is used to force the rollback of a transaction that may be corrupt or in doubt. With this clause, you specify the transaction ID in single quotes as string. You can find the transaction ID in the system view called DBA_2PC_PENDING.

 


All Chapters
Author