ROLLBACK

ROLLBACK — end the current transaction and undo the effect of any DML and DDL statements that was done in the current transaction.

Syntax

ROLLBACK [ WORK ]

ROLLBACK TO SAVEPOINT savepoint_name

Description

Stops and ends the current transaction. Use the ROLLBACK statement to stop a transaction and undo work done in the current transaction, or undo the work done after a specified savepoint. Execution of ROLLBACK discards any DML updates made by the transaction being stopped.
ROLLBACK with no arguments releases all named savepoints within the transaction.
If autocommit is off or if you specified START TRANSACTION (see START TRANSACTION), specify COMMIT (see COMMIT) to commit the work done in the transaction and end the transaction.

NuoDB recommends that you explicitly end transactions in application programs using either a COMMIT or ROLLBACK statement. If you do not explicitly commit the transaction and the program terminates abnormally then NuoDB will rollback the current uncommitted transaction.

To roll back your current transaction, no privileges are necessary.

See SAVEPOINT for more information about savepoints.

Parameters

WORK

This keyword is ignored. ROLLBACK WORK is the same as just ROLLBACK.

savepoint_name

Name of SAVEPOINT that you want to be able to specify with ROLLBACK TO SAVEPOINT. Only those changes made after the savepoint are undone.

Examples

Example 1: Each statement is committed upon execution and therefore a roll back is not possible.
SHOW AUTOCOMMIT
    Autocommit is on
CREATE TABLE t1 (f1 int);
INSERT INTO t1 VALUES (1);
SELECT * FROM t1;
 F1
 ---
  1

ROLLBACK;   /* ROLLBACK does nothing because the work is already committed. */
SELECT * FROM t1;
 F1
 ---
  1
Example 2: Autocommit is off and work can be rolled back.

This example uses table created in the first example.

SHOW AUTOCOMMIT
    Autocommit is off

INSERT INTO t1 VALUES (2);
SELECT * FROM t1;
 N
 --
 1
 2

ROLLBACK;
SELECT * FROM t1;
 N
 --
 1