SET TRANSACTION

The SET TRANSACTION statement sets the isolation level, read only attribute, or diagnostics area size for the current unit of work.

Invocation

This statement can be embedded within an application program or issued interactively. It is an executable statement that can be dynamically prepared.

Authorization

None required.

Syntax

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram>>-SET TRANSACTION---------------------------------------------->
 
   .-,-----------------------------------------.
   V                    .-SERIALIZABLE-----.   | (1)
>----+-ISOLATION LEVEL--+-NO COMMIT--------+-+-+---------------><
     |                  +-READ UNCOMMITTED-+ |
     |                  +-READ COMMITTED---+ |
     |                  '-REPEATABLE READ--' |
     | .-READ ONLY--.                        |
     +-+-READ WRITE-+------------------------+
     '-DIAGNOSTICS SIZE--+-integer--+--------'
                         '-variable-'
 
Notes:
  1. Only one ISOLATION LEVEL clause, one READ WRITE or READ ONLY clause, and one DIAGNOSTICS SIZE clause may be specified.

Description

ISOLATION LEVEL
Specifies the isolation level of the transaction. If the ISOLATION LEVEL clause is not specified, ISOLATION LEVEL SERIALIZABLE is implicit
NO COMMIT
Specifies isolation level NC (COMMIT(*NONE)).
READ UNCOMMITTED
Specifies isolation level UR (COMMIT(*CHG)).
READ COMMITTED
Specifies isolation level CS (COMMIT(*CS)).
REPEATABLE READ 82
Specifies isolation level RS (COMMIT(*ALL)).
SERIALIZABLE
Specifies isolation level RR (COMMIT(*RR)).
READ WRITE or READ ONLY
Specifies whether the transaction allows data change operations.
READ WRITE
Specifies that all SQL operations are allowed. This is the default unless ISOLATION LEVEL READ UNCOMMITTED is specified.
READ ONLY
Specifies that only SQL operations that do not change SQL data are allowed. If ISOLATION LEVEL READ UNCOMMITTED is specified, this is the default.
DIAGNOSTICS SIZE
Specifies the maximum number of GET DIAGNOSTICS condition areas for the current transaction. The GET DIAGNOSTICS statement-information-item MORE will be set to 'Y' for the current statement if the statement exceeds the maximum number of condition areas for the current transaction. The specified maximum number of condition areas must be between 1 and 32767.
integer
An integer constant that specifies the maximum number of condition areas for the current transaction.
variable
Identifies a variable which contains the maximum number of condition areas for the current transaction. The variable must be a numeric variable with a zero scale and must not be followed by an indicator variable.

Notes

Scope of SET TRANSACTION: The SET TRANSACTION statement sets the isolation level for SQL statements for the current activation group of the process. If that activation group has commitment control scoped to the job, then the SET TRANSACTION statement sets the isolation level of all other activation groups with job commit scoping as well.

If an isolation clause is specified in an SQL statement, that isolation level overrides the transaction isolation level and is used for the SQL statement.

The scope of the SET TRANSACTION statement is based on the context in which it is run. If the SET TRANSACTION statement is run in a trigger, the isolation level specified applies to all subsequent SQL statements until another SET TRANSACTION statement occurs or until the trigger completes, whichever happens first. If the SET TRANSACTION statement is run outside a trigger, the isolation level specified applies to all subsequent SQL statements (except those statements within a trigger that are executed after a SET TRANSACTION statement in the trigger) until a COMMIT or ROLLBACK operation occurs.

For more information about isolation levels, see Isolation level.

SET TRANSACTION restrictions: The SET TRANSACTION statement can only be executed when it is the first SQL statement in a unit of work, unless:

In a trigger, SET TRANSACTION with READ ONLY is allowed only on a COMMIT boundary. The SET TRANSACTION statement can be executed in a trigger at any time, but it is recommended that it be executed as the first statement in the trigger. The SET TRANSACTION statement is useful within triggers to set the isolation level for SQL statements in the trigger to the same level as the application which caused the trigger to be activated.

A SET TRANSACTION statement is not allowed if the current connection is to a remote application server unless it is in a trigger at the current server. Once a SET TRANSACTION statement is executed, CONNECT and SET CONNECTION statements are not allowed until the unit of work is committed or rolled back.

The SET TRANSACTION statement has no effect on WITH HOLD cursors that are still open when the SET TRANSACTION statement is executed.

Syntax alternatives: The following keywords are synonyms supported for compatibility to prior releases. These keywords are non-standard and should not be used:

Examples

Example 1: The following SET TRANSACTION statement sets the isolation level to NONE (equivalent to specifying *NONE on the SQL precompiler command).

   EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT;

Example 2: The following SET TRANSACTION statement sets the isolation level to SERIALIZABLE.

   SET TRANSACTION ISOLATION LEVEL SERIALIZABLE


82.
REPEATABLE READ is the ISO and ANS standard term that corresponds to the isolation level of *ALL for DB2 UDB for iSeries and the isolation level of Read Stability (RS) in IBM® SQL. SERIALIZABLE is used in the ISO and ANS standard for what IBM SQL calls Repeatable Read (RR).



[ Top of Page | Previous Page | Next Page | Contents | Index ]