SQL Reference

ROLLBACK

The ROLLBACK statement is used to back out of the database changes that were made within a unit of work or a savepoint.

Invocation

This statement can be embedded in an application program or issued through the use of dynamic SQL statements. It is an executable statement that can be dynamically prepared.

Authorization

None required.

Syntax

               .-WORK--.
>>-ROLLBACK----+-------+---------------------------------------->
 
>-----+------------------------------------+-------------------><
      '-TO SAVEPOINT--+-----------------+--'
                      '-savepoint-name--'
 

Description

The unit of work in which the ROLLBACK statement is executed is terminated and a new unit of work is initiated. All changes made to the database during the unit of work are backed out.

The following statements, however, are not under transaction control and changes made by them are independent of issuing the ROLLBACK statement:

TO SAVEPOINT
Indicates that a partial rollback (ROLLBACK TO SAVEPOINT) is to be performed. If no savepoint is active, an SQL error is returned (SQLSTATE 3B502). After a successful ROLLBACK, the savepoint continues to exist. If a savepoint-name is not provided, rollback is to the most recently set savepoint.

If this clause is omitted, the ROLLBACK WORK statement rolls back the entire transaction. Furthermore, savepoints within the transaction are released.

savepoint-name
Indicate the savepoint to which to rollback. After a successful ROLLBACK, the savepoint defined by savepoint-name continues to exist. If the savepoint name does not exist, an error is returned (SQLSTATE 3B001). Data and schema changes made since the savepoint was set are undone.

Notes

Example

Delete the alterations made since the last commit point or rollback.

   ROLLBACK WORK


Footnotes:

104
A FETCH must be performed before a positioned UPDATE or DELETE statement is issued.


[ Top of Page | Previous Page | Next Page ]