Undoing selected changes within a unit of work by using savepoints
Savepoints enable you to undo selected changes within a unit of work. Your application can set any number of savepoints and then specify a specific savepoint to indicate which changes to undo within the unit of work.
Procedure
To undo selected changes within a unit of work by using savepoints:
Examples
Rolling back to the most recently created savepoint: When the ROLLBACK TO SAVEPOINT statement is executed
in the following code, DB2 rolls
back work to savepoint B.
EXEC SQL SAVEPOINT A;
...
EXEC SQL SAVEPOINT B;
...
EXEC SQL ROLLBACK TO SAVEPOINT;
Setting savepoints during distributed processing: An
application performs the following tasks:
- Sets savepoint C1.
- Does some local processing.
- Executes a CONNECT statement to connect to a remote site.
- Sets savepoint C2.
Setting multiple savepoints with the same name: Suppose
that the following actions occur within a unit of work:
- Application A sets savepoint S.
- Application A calls stored procedure P.
- Stored procedure P sets savepoint S.
- Stored procedure P executes the following statement: ROLLBACK TO SAVEPOINT S