Atomic batches of work
A transaction is a group of statements treated as one atomic unit: either all of them apply or none of them do. SQLite is fully ACID by default — even a single statement runs inside an implicit transaction.
Three explicit shapes:
BEGIN; ... COMMIT;— explicit transaction, commit on success.BEGIN; ... ROLLBACK;— abort all changes since BEGIN.- SAVEPOINT — nested transaction-like checkpoint inside an outer transaction;
RELEASEon success,ROLLBACK TOon failure.
SQLite's transaction modes:
- DEFERRED (default) — locks acquired only when needed.
- IMMEDIATE — write lock acquired at BEGIN; other writers block immediately.
- EXCLUSIVE — exclusive lock; other readers and writers block.
Tip: For 'either I write everything or I write nothing' workflows where you might race another writer, use
BEGIN IMMEDIATE. The default DEFERRED can fail at COMMIT time with SQLITE_BUSY if another writer beat you to it — IMMEDIATE fails fast at BEGIN.