How do SQLite savepoints support partial rollback inside a transaction?
Quick answer
A savepoint is a named mark you can return to within a transaction. ROLLBACK TO name undoes changes made after the most recent matching savepoint, but does not end the whole transaction or remove that savepoint. Later savepoints are canceled. RELEASE name removes that savepoint and any nested ones; releasing an inner savepoint is not a commit. Releasing the outermost savepoint commits. [S1]
The question, the details, the next step.
A practical checklist
Mark which earlier changes should survive a partial rollback.
Name savepoints so each rollback target is clear.
Check which later savepoints a rollback will cancel.
After
ROLLBACK TO, account for the fact that the target savepoint remains.Confirm whether each
RELEASEis inner or outermost before running it.Try the intended control-flow paths with disposable data.
A few more useful answers
Does `ROLLBACK TO` remove the savepoint I named?
No. It restores the state to just after the most recent matching savepoint, but leaves that savepoint available. Later savepoints are canceled. [S1]
Does releasing an inner savepoint commit its changes?
No. Releasing an inner savepoint removes it and nested savepoints, but does not itself commit changes to the database file. Releasing the outermost savepoint commits. [S1]
Can I use the example unchanged in my application?
Treat the table and SKU names as illustrative placeholders, and verify that the updates match your schema and intended behavior. The example explains savepoint control flow, not what your application should change.
Sources
References used for this guide.
- [S1] SQLite Savepoints sqlite.org · Checked
