Using Transactions¶
A transaction groups a series of changes into a single, all-or-nothing operation: either every change is saved, or none of them are. Transactions are what keep a database consistent when several related statements must succeed together — for example, when you move an order to a different customer and the orders row and its items rows must all be updated, or none at all.
By default, SQLite runs in autocommit mode: every statement is saved immediately and permanently. When you start a transaction, autocommit is suspended and your changes are held provisionally until you either commit them (make them permanent) or roll them back (discard them). This gives you a safety net while you make bulk edits, import data, or test a script.
SQLite has supported atomic commit and rollback since version 2.0. Since version 3.6.8 it also supports savepoints — named markers inside a transaction that let you undo part of your work without abandoning the whole transaction, a form of nested transaction.
You can drive transactions entirely from the Transaction menu, or by running the equivalent commands (BEGIN, COMMIT, ROLLBACK, SAVEPOINT, RELEASE) yourself on the SQL tab.
In this section¶
- Starting a transaction
- Committing a transaction
- Rolling back a transaction
- Creating a savepoint
- Releasing a savepoint
- Rolling back to a savepoint
Note
Transactions apply to the currently selected database. If you have several databases open, each one has its own independent transaction state.