Using Savepoints within Transactions
📖 Scenario: You are managing a simple bank database where you need to update account balances carefully. Sometimes, you want to save your progress during a transaction so you can undo part of it if needed without losing all changes.
🎯 Goal: Build a SQL transaction that uses savepoints to partially rollback changes if an error occurs, ensuring the database stays consistent.
📋 What You'll Learn
Create a transaction using
BEGIN and COMMITSet a savepoint named
sp1 after the first updatePerform a second update after the savepoint
Rollback to the savepoint
sp1 if the second update failsCommit the transaction at the end
💡 Why This Matters
🌍 Real World
Savepoints help manage complex database changes safely, allowing partial undo without losing all progress.
💼 Career
Database administrators and developers use savepoints to ensure data integrity during multi-step operations.
Progress0 / 4 steps