rollback

Description

Rolls a transaction back to a savepoint inside the transaction or to the beginning of the transaction.

Syntax

exec sql [at connection_name] 
 rollback [transaction | tran | work] 
 [transaction_name | savepoint_name] end-exec

Parameters

transaction | trans | work

The keywords transaction, trans, and work are interchangeable in the rollback statement, but only work is ANSI-compliant.

transaction_name

The name of the transaction being rolled back.

savepoint_name

The name assigned to the savepoint in a save transaction statement. If you omit savepoint_name, Adaptive Server rolls back the entire transaction.

Examples

Example 1

               ...
 
           EXEC SQL CONNECT "user" IDENTIFIED BY "password"
                AT connect1 USING "srvname" END-EXEC.
 
                ...
 
           EXEC SQL AT connect1 UPDATE test SET col1 = 'x' END-EXEC.
           IF SQLCODE = 0
                DISPLAY "ROWS UPDATED = ",SQLERRD(3)
           ELSE
      DISPLAY "AN ERROR OCCURED -",SQLERRMC
                ESQL SQL AT connect1 ROLLBACK TRANSACTION END-EXEC
           END-IF.

Usage

See also

begin transaction, commit