The ROLLBACK statement is used to end a unit of work and to back out the database changes that were made by that unit of work.
This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.
ROLLBACK is not allowed in a trigger program if the trigger program and the triggering program are run under the same commitment definition. ROLLBACK is not allowed in an external procedure if the external procedure and the program that issued the CALL statement run under the same commitment definition.
None required.
.-WORK-.
>>-ROLLBACK--+------+----+-------+-----------------------------><
'-HOLD--'
The ROLLBACK statement ends the unit of work in which it is executed and starts a new unit of work. All changes made by ALTER, CALL, COMMENT ON, CREATE, DELETE, DROP (except for DROP COLLECTION), GRANT, INSERT, LABEL ON, RENAME, REVOKE, and UPDATE statements executed during the unit of work are backed out.
The following are true under this unit of work's commitment definition if HOLD is omitted:
At the end of a ROLLBACK HOLD, the cursor position is the same as it was at the start of the unit of work.
The ending of the default activation group causes an implicit rollback. Thus, an explicit COMMIT or ROLLBACK statement should be issued before the end of the default activation group.
A ROLLBACK is automatically performed when:
If the unit of work is in the prepared state because a COMMIT was in progress when the failure occurred, a rollback is not performed. Instead, resynchronization of all the connections involved in the unit of work will occur. For more information, see the book Backup and Recovery, SC41-5304-04.
If the unit of work is in the prepared state because a COMMIT was in progress when the failure occurred, a rollback is not performed. Instead, resynchronization of all the connections involved in the unit of work will occur. For more information, see the book Backup and Recovery, SC41-5304-04.
A unit of work may include the processing of up to and including 4 million rows, including rows retrieved during a SELECT INTO or FETCH statement45, and rows inserted, deleted, or updated as part of INSERT, DELETE, and UPDATE operations. 46
The commit and rollback operations do not affect the DROP COLLECTION statement, and this statement is not, therefore, allowed in an application program that also specifies COMMIT(*CHG), COMMIT(*CS), COMMIT(*ALL), or COMMIT(*RR).
See the notes to the COMMIT statement for information on determining which commitment definition is used by SQL.
Any cursors associated with a prepared statement that is destroyed cannot be opened until the statement is prepared again. ROLLBACK has no effect on the state of connections.
If, within a unit of work, a CLOSE is followed by a ROLLBACK, all changes made within the unit of work are backed out. The CLOSE itself is not backed out and the file is not reopened.
See the examples under COMMIT on page *** for examples using the ROLLBACK statement.