Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
In standard transactional workflows, a ROLLBACK cancels the entire transaction from the very beginning. However, in complex multi-step enterprise business processes, you may want to rollback only a specific sub-operation while retaining earlier successful steps.
MySQL achieves this partial rollback capability through Savepoints.
A Savepoint is a named marker set inside an active transaction. It acts as a checkpoint to which the transaction can be partially rewound without discarding earlier work.
MySQL does not support true nested transactions; if you issue a second START TRANSACTION, MySQL implicitly commits the first one. Savepoints provide the exact nested rollback behavior developers need without starting a new transaction.
Suppose a travel platform processes a vacation package booking:
ROLLBACK TO SAVEPOINT name; does NOT end or commit the transaction. Locks remain held and subsequent SQL statements can still be executed before the final COMMIT.ROLLBACK TO SAVEPOINT A, Savepoint B is destroyed.RELEASE SAVEPOINT vs ROLLBACK TO:ROLLBACK TO SAVEPOINT sp1 rolls back changes made after sp1.RELEASE SAVEPOINT sp1 merely frees the savepoint marker from memory without modifying any data.COMMIT or full ROLLBACK to terminate the overall transaction.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Transaction Control: START TRANSACTION, COMMIT, ROLLBACK | Transaction Isolation Levels in MySQL |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.