Name
BEGIN TRANSACTION — Open an explicit transaction
Syntax
Common Usage
BEGIN; BEGIN EXCLUSIVE TRANSACTION;
Description
The BEGIN
TRANSACTION
command starts an explicit
transaction. Once started, an explicit transaction will remain
open until the transaction is either committed using COMMIT TRANSACTION
, or rolled
back using ROLLBACK
TRANSACTION
. Transactions are used to group
multiple discrete commands (such as a sequence of INSERT
commands that insert rows
into cross-referenced tables) into a single logical
command.
Transactions are ACID-compliant, in that they are atomic, consistent, isolated, and durable. They’re an important part of correct database design and database use. For more information, see Transaction Control Language.
All changes and modifications to a database are done within a transaction. Normally, SQLite is in autocommit mode. In this mode, each and every statement that might modify the database is automatically wrapped in its own transaction. Each command begins a transaction, executes the given command statement, and attempts to commit the changes. If any error occurs, the wrapper transaction is rolled back.
The BEGIN
command turns off autocommit mode,
opening a transaction and leaving it open until it is explicitly
committed or rolled back. This allows multiple commands (and
multiple modifications) to be packaged into a single
transaction. Once a COMMIT
or
ROLLBACK ...
Get Using SQLite now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.