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.

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

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.