Rollback — Complete Guide
Rollback — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 48 of 100
Rollback
Basics ✓ → Advanced
Advanced · 2 — Production · ~6 min · MySQL — Transactions & Concurrency
What is this?
ROLLBACK ends a transaction and discards uncommitted changes since START TRANSACTION (or since a SAVEPOINT). Committed work from earlier transactions stays.
Why should you care?
Payment gateway timeout means order must not persist — ROLLBACK clears pending inserts and restores locked stock.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
START TRANSACTION;
UPDATE products SET stock_qty = stock_qty - 1 WHERE product_id = 5;
INSERT INTO orders (customer_id, order_ref, total_inr) VALUES (1, 'DF-FAIL', 999.00);
-- Gateway declined
ROLLBACK;
SELECT stock_qty FROM products WHERE product_id = 5;
What happened?
- After ROLLBACK, stock update vanishes as if txn never ran.
- orders row not inserted.
- SELECT shows original stock_qty — critical for failed checkout paths.
Practice next
- Note stock before txn.
- Run update + insert then ROLLBACK.
- Confirm stock and orders unchanged.
- Use ROLLBACK in stored procedure handler on SQLEXCEPTION.
- Pair try/catch in app with conn.rollback().
Remember
ROLLBACK = abort current transaction. Uncommitted changes disappear. Always rollback on unhandled app errors.
DataFlow failed UPI
Node service catches gateway 402 and issues ROLLBACK on MySQL connection.
Outcome: Inventory and order tables stay consistent with payment state.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!