BEGIN statement initiates a transaction, which either successfully executes all of the statements it contains or none at all.
When running under the default
SERIALIZABLE isolation level, your application should use a retry loop to handle transaction retry errors that can occur under contention.Synopsis
Required privileges
No privileges are required to initiate a transaction. However, privileges are required for each statement within a transaction.Aliases
In CockroachDB, the following are aliases for theBEGIN statement:
BEGIN TRANSACTIONSTART TRANSACTION
Parameters
Examples
Begin a transaction
Use default settings
Without modifying theBEGIN statement, the transaction uses SERIALIZABLE isolation and NORMAL priority.
This example assumes you’re using client-side retry handling.
Change isolation level
You can set the transaction isolation level toSERIALIZABLE or READ COMMITTED.
If not specified, transactions use the value of the current session’s default_transaction_isolation variable.
Change priority
You can set a transaction’s priority toLOW or HIGH.
SET TRANSACTION.
This example assumes you’re using client-side retry handling.
Use the AS OF SYSTEM TIME option
You can execute the transaction using the database contents “as of” a specified time in the past.
Begin a transaction with automatic retries
CockroachDB will automatically retry all transactions that contain bothBEGIN and COMMIT in the same batch. Batching is controlled by your driver or client’s behavior, but means that CockroachDB receives all of the statements as a single unit, instead of a number of requests.
From the perspective of CockroachDB, a transaction sent as a batch looks like this:

