ROLLBACK
The ROLLBACK
statement undoes all changes made by the current transaction, reverting the database to its previous state.
Example: Using ROLLBACK
BEGIN TRANSACTION;
UPDATE FreedomFighters SET City = 'Trichy' WHERE Name = 'Banumathi';
ROLLBACK;
Output:
Changes are undone, and the City
for Banumathi
remains unchanged.
Do's and Don'ts
Do's
- Use
ROLLBACK
to revert changes when errors occur during a transaction. - Ensure that rollback is part of error handling to maintain data consistency.
Don'ts
- Don't assume rollback will always work if auto-commit is enabled.
- Don't use rollback excessively; plan transactions carefully.