Rolls back to a savepoint.

Syntax

ROLLBACK [ WORK ] TO [ SAVEPOINT ] savepoint_name

Description

You can use the ROLLBACK TO SAVEPOINT command to roll back all commands that are run after the specified savepoint is created. The savepoint remains valid and can be rolled back to again later if needed.

ROLLBACK TO SAVEPOINT implicitly deletes all savepoints that are created after the specified savepoint.

Parameters

Parameter Description
savepoint_name The savepoint to which to roll back.

Notes

An error occurs if you specify a savepoint name that does not exist.

SPL programs do not support ROLLBACK TO SAVEPOINT.

Examples

Undo the effects of commands that are run after the depts savepoint:

\set AUTOCOMMIT off
INSERT INTO dept VALUES (50, 'HR', 'NEW YORK');
SAVEPOINT depts;
INSERT INTO emp (empno, ename, deptno) VALUES (9001, 'JONES', 50);
INSERT INTO emp (empno, ename, deptno) VALUES (9002, 'ALICE', 50);
ROLLBACK TO SAVEPOINT depts;