What if you could undo mistakes in your database as easily as pressing Ctrl+Z?
Why COMMIT and ROLLBACK behavior in SQL? - Purpose & Use Cases
Imagine you are updating a long list of customer orders in a notebook. If you make a mistake halfway, you have to erase everything manually or start over. There is no easy way to undo just the last few changes.
Manually tracking changes is slow and risky. You might miss errors or accidentally keep wrong data. Fixing mistakes means rewriting or erasing many pages, which wastes time and causes frustration.
COMMIT and ROLLBACK let you control when changes become permanent or get undone. You can try updates safely, and if something goes wrong, just ROLLBACK to the previous correct state without hassle.
Update orders one by one and rewrite if error found
BEGIN TRANSACTION; UPDATE orders SET status='shipped'; -- if error ROLLBACK; else COMMIT;
This behavior lets you make safe, reversible changes to your data, avoiding costly mistakes and keeping your database reliable.
When booking a flight, the system updates seat availability and payment info together. If payment fails, ROLLBACK cancels the seat hold, preventing errors.
Manual updates are error-prone and hard to fix.
COMMIT saves changes permanently.
ROLLBACK undoes changes to keep data safe.