SyntaxStudy
Sign Up
MySQL Intermediate 4 min read

COMMIT and ROLLBACK

COMMIT / ROLLBACK

COMMIT persists all changes. ROLLBACK undoes all changes since the last COMMIT or START TRANSACTION. Savepoints allow partial rollbacks.

Example
START TRANSACTION;
UPDATE inventory SET qty = qty - 1 WHERE product_id = 10;
SAVEPOINT after_inventory;

INSERT INTO shipments (product_id, qty) VALUES (10, 1);
-- Something fails:
ROLLBACK TO SAVEPOINT after_inventory;   -- keeps inventory update
-- Or full rollback:
ROLLBACK;
-- Or commit everything:
COMMIT;
Pro Tip

ROLLBACK TO SAVEPOINT does not end the transaction — you can still COMMIT or ROLLBACK further.