• Data Warehouse Service

dws
  1. Help Center
  2. Data Warehouse Service
  3. Developer Guide
  4. SQL Reference
  5. SQL Syntax
  6. START TRANSACTION

START TRANSACTION

Function

START TRANSACTION starts a transaction. If the isolation level, read/write mode, or deferrable mode is specified, a new transaction will have those characteristics. You can also specify them using SET TRANSACTION.

Precautions

None

Syntax

Format 1: START TRANSACTION

START TRANSACTION
  [ 
    { 
       ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ }
       | { READ WRITE | READ ONLY }
     } [, ...] 
  ];

Format 2: BEGIN

BEGIN [ WORK | TRANSACTION ]
  [ 
    { 
       ISOLATION LEVEL { READ COMMITTED | READ UNCOMMITTED | SERIALIZABLE | REPEATABLE READ }
       | { READ WRITE | READ ONLY }
      } [, ...] 
  ];

Parameter Description

  • WORK | TRANSACTION

    Optional keyword in BEGIN format without functions.

  • ISOLATION LEVEL

    Specifies the transaction isolation level that determines the data that a transaction can view if other concurrent transactions exist.

    NOTE:

    The isolation level of a transaction cannot be reset after the first clause (INSERT, DELETE, UPDATE, FETCH) for modifying data is executed in the transaction.

    Value range:

    • READ COMMITTED: Only submitted data can be read. This is the default.
    • READ UNCOMMITTED: Unsubmitted data is probably read. This isolation level is provided to handle CN breakdown emergencies. On this isolation level, you are advised to only read data to prevent inconsistency.
    • REPEATABLE READ: Currently, the isolation level is not supported in DWS. It is equivalent to READ COMMITTED.
    • SERIALIZABLE: Currently, the isolation level is not supported in DWS. It is equivalent to READ COMMITTED.
  • READ WRITE | READ ONLY

    Specifies the transaction access mode (read/write or read only).

Example

-- Start a transaction in default mode.
START TRANSACTION;
SELECT * FROM tpcds.reason;
END;

-- Start a transaction in default mode.
BEGIN;
SELECT * FROM tpcds.reason;
END;

-- Start a transaction with the isolation level being READ COMMITTED and the access mode being READ WRITE.
START TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE;
SELECT * FROM tpcds.reason;
COMMIT;

Helpful Links

COMMIT, ROLLBACK, SET TRANSACTION