Cover by Jay A. Kreibich

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Name

BEGIN TRANSACTION — Open an explicit transaction

Syntax

image with no caption

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 ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required