MySQL + SQL · Lesson 84

COMMIT, ROLLBACK and SAVEPOINT

Transaction Control Commands

CommandDoes
COMMITpermanently save all changes
ROLLBACKundo changes since the transaction began
SAVEPOINTmark a point to roll back to partially

Using SAVEPOINT

START TRANSACTION;
UPDATE students SET marks = 90 WHERE roll_no = 1;
SAVEPOINT sp1;
UPDATE students SET marks = 0 WHERE roll_no = 2;  -- mistake!
ROLLBACK TO sp1;   -- undo only the second update
COMMIT;            -- keep the first update
SAVEPOINT lets you undo part of a transaction without losing everything.

Summary

  • COMMIT saves; ROLLBACK undoes; SAVEPOINT marks a partial undo point.
  • ROLLBACK TO savepoint undoes only changes after that point.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp