You are viewing the documentation for a prerelease version.

ROLLBACK TRANSACTION

    +
    The ROLLBACK TRANSACTION statement enables you to rollback a transaction.

    Purpose

    The ROLLBACK TRANSACTION statement enables you to rollback an ACID transaction. You can rollback the entire transaction, or rollback to a previous savepoint. Refer to Transactions for further information.

    This statement may only be used within a transaction.

    If you are using the Query Workbench or the Query REST API, you must set the txid query parameter to specify the transaction ID.

    If you are using the cbq shell, you don’t need to specify the transaction ID. Once you have started a transaction, all statements within the cbq shell session are assumed to be part of the same transaction until you rollback or commit the transaction. [1]

    When you rollback the entire transaction, this statement removes all savepoints within the transaction.

    If you are using the cbq shell, and a transaction fails for any reason, you must use the ROLLBACK TRANSACTION statement to remove the transaction context and reset the transaction ID.

    Syntax

    rollback-transaction ::= ROLLBACK [ WORK | TRAN | TRANSACTION ] [ TO SAVEPOINT savepointname ]
    'ROLLBACK' ( 'WORK' | 'TRAN' | 'TRANSACTION' )? ( 'TO' 'SAVEPOINT' savepointname )?

    The WORK, TRAN, and TRANSACTION keywords are synonyms. These keywords are optional; you may include one of these keywords, or omit them entirely.

    Rollback to a Savepoint

    The TO SAVEPOINT clause enables you to rollback to a specified savepoint. This clause is optional. If omitted, the entire transaction is rolled back.

    savepointname

    An identifier specifying a name for the savepoint.

    Examples

    Example 1. Rollback a transaction — cbq shell
    Request
    cbq> ROLLBACK TRANSACTION TO SAVEPOINT s1;
    Example 2. Rollback a transaction — REST API
    CURL request
    $ curl http://localhost:8093/query/service \
    -u Administrator:password \
    -H 'Content-Type: application/json' \
    -d '{
      "statement": "ROLLBACK TRANSACTION TO SAVEPOINT s1;",
      "pretty": true,
      "txid": "d81d9b4a-b758-4f98-b007-87ba262d3a51" (1)
    }'
    1 The transaction ID generated when the transaction began.

    1. You must be using cbq shell version 2.0 or above to use the automatic transaction ID functionality.