ROLLBACK is a Transaction Control Language (TCL) command that cancels all uncommitted changes made during the current transaction and restores the database to its previous consistent state.
ROLLBACK protects business data by allowing accidental or failed operations to be completely reversed before they become permanent.
While updating employee salaries, an incorrect calculation is detected before COMMIT. The transaction is rolled back, restoring the original salary values.
BEGIN TRANSACTION;
UPDATE Employees
SET Salary = Salary * 1.50;
ROLLBACK;
ROLLBACK is commonly used in banking systems, financial applications, payroll processing, inventory management, healthcare software, and enterprise applications to recover from errors.
- Cancels uncommitted changes.
- Restores the previous database state.
- Protects against accidental updates.
- Works only before COMMIT.
- Improves data reliability.
- Commonly used for error recovery.
- Essential for transaction management.
What does ROLLBACK do?
ROLLBACK cancels all uncommitted changes made during the current transaction.
Can ROLLBACK undo committed changes?
No. Once COMMIT has been executed, the changes cannot be rolled back.