BEGIN TRANSACTION statement

Syntax

BEGIN TRANSACTION [ISOLATION LEVEL level]
   [statements]

Description

Use the BEGIN TRANSACTION statement to indicate the beginning of a transaction.

The ISOLATION LEVEL clause sets the transaction isolation level for the duration of that transaction. The isolation level reverts to the original value at the end of the transaction.

level is an expression that evaluates to one of the following:

  • An integer from 0 through 4
  • One of the following keywords
    Table 1. Keywords
    Integer Keyword Effect on This Transaction
    0 NO.ISOLATION Prevents lost updates.1
    1 READ.UNCOMMITTED Prevents lost updates.
    2 READ.COMMITTED Prevents lost updates and dirty reads.
    3 REPEATABLE.READ Prevents lost updates, dirty reads, and nonrepeatable reads.
    4 SERIALIZABLE Prevents lost updates, dirty reads, nonrepeatable reads, and phantom writes.

    1Lost updates are prevented if the ISOMODE configurable parameter is set to 1 or 2.

Examples

The following examples both start a transaction at isolation level 3:

BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE.READ
BEGIN TRANSACTION ISOLATION LEVEL 3