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 Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Number Bonds to 10 → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts (0s, 1s, 2s, 5s, 10s) → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Comparing and Ordering Integers → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Integer Order of Operations → Variable Expressions → The Distributive Property → Variables and Expressions Review → Introduction to Polynomials → Adding and Subtracting Polynomials → Multiplying Polynomials → Factorial → Permutations → Combinations → Counting Principles: Addition and Multiplication Rules → Introduction to Graph Theory → Propositional Logic Foundations → Logical Equivalences → Boolean Algebra → Boolean Type and Truth Values → Comparison Operators and Boolean Tests → Logical Operators and Boolean Algebra → Conditional Statements → Defining and Calling Functions → Functions: Decomposing Problems → Function Parameters and Argument Passing → Return Values → Error Handling and Exceptions → File I/O Basics → File System Concepts → Database Transactions → Savepoints: Partial Rollback Within Transactions

Longest path: 82 steps · 357 total prerequisite topics

Prerequisites (1)

Leads To (0)

No topics depend on this one yet.