A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Savepoints: Partial Rollback Within Transactions

College Depth 81 in the knowledge graph I know this Set as goal
357prerequisites beneath it
See this on the map →
Database Transactions
transactions rollback error-handling

Core Idea

Savepoints mark points within a transaction to which a ROLLBACK can be selective, allowing recovery from errors without losing all work in the transaction.

How It's Best Learned

Create a multi-statement transaction with savepoints and practice rolling back to different points.

Common Misconceptions

Savepoints do not commit data—only COMMIT finalizes changes. Rolled-back statements after a savepoint can be re-executed with different values.

Explainer

From your work with BEGIN, COMMIT, and ROLLBACK, you know that a transaction groups multiple operations into an atomic unit — either everything succeeds and is committed, or everything is rolled back as if nothing happened. But what if your transaction contains ten steps, step seven fails, and you want to undo just step seven while keeping the first six? Without savepoints, your only option is to roll back the entire transaction and start over. Savepoints solve this by letting you place named bookmarks inside a transaction that you can roll back to selectively.

The syntax is straightforward: after beginning a transaction, you create a savepoint with `SAVEPOINT my_checkpoint`. You continue executing statements, and if something goes wrong, you issue `ROLLBACK TO SAVEPOINT my_checkpoint`. This undoes everything *after* that savepoint while preserving everything before it. You can then continue the transaction from that point — retrying the failed operation with different values, skipping it entirely, or taking an alternative path. Think of it like saving your progress in a video game: if you die in a tough section, you reload from the last save rather than restarting the entire game.

You can create multiple savepoints within a single transaction, effectively nesting recovery points. Imagine a batch import that processes records one at a time: you set a savepoint before each record, attempt the insert, and if a particular record violates a constraint, you roll back to its savepoint and log the failure without losing the successfully imported records. This pattern is essential in applications that process data in bulk where individual failures are expected and acceptable.

The critical thing to remember is that savepoints do not commit anything. All the work inside the transaction — including everything before your savepoints — remains uncommitted until you issue a final COMMIT. A savepoint is not a mini-transaction; it is a recovery marker within the larger transaction. If you ROLLBACK the entire transaction (without specifying a savepoint), everything is undone regardless of how many savepoints you set. Savepoints give you *finer-grained error recovery* within the transactional model you already understand, without breaking the atomicity guarantee that transactions provide.

Practice Questions 5 questions

Prerequisite Chain

Understanding ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Number Bonds to 10Addition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts (0s, 1s, 2s, 5s, 10s)Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineComparing and Ordering IntegersAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsInteger Order of OperationsVariable ExpressionsThe Distributive PropertyVariables and Expressions ReviewIntroduction to PolynomialsAdding and Subtracting PolynomialsMultiplying PolynomialsFactorialPermutationsCombinationsCounting Principles: Addition and Multiplication RulesIntroduction to Graph TheoryPropositional Logic FoundationsLogical EquivalencesBoolean AlgebraBoolean Type and Truth ValuesComparison Operators and Boolean TestsLogical Operators and Boolean AlgebraConditional StatementsDefining and Calling FunctionsFunctions: Decomposing ProblemsFunction Parameters and Argument PassingReturn ValuesError Handling and ExceptionsFile I/O BasicsFile System ConceptsDatabase TransactionsSavepoints: Partial Rollback Within Transactions

Longest path: 82 steps · 357 total prerequisite topics

Prerequisites (1)

Leads To (0)

No topics depend on this one yet.