ROLLBACK Statement

The ROLLBACK statement is used to undo changes made by the current transaction. It reverts the database to the state it was in before the transaction started.

Example: Using ROLLBACK

DELETE FROM FreedomFighters
WHERE City = 'Madurai';
ROLLBACK;

Output:

Changes are undone, and the records from Madurai are not deleted.

Do's and Don'ts

Do's

  • Use ROLLBACK to revert changes when errors occur during a transaction.
  • Test transactions thoroughly before committing to avoid the need for rollback.

Don'ts

  • Don't assume all changes can be rolled back if auto-commit is enabled.
  • Don't use ROLLBACK excessively, as it can be disruptive to long-running transactions.