天天看点

第二章 SQL命令参考-ROLLBACK TO SAVEPOINT

ROLLBACK TO SAVEPOINT

Rolls back thecurrent transaction to a savepoint.

概要

ROLLBACK [WORK| TRANSACTION] TO [SAVEPOINT]

描述

此命令将回滚在保存点建立后执行的所有命令。 保存点保持有效,如果需要,可以稍后回滚。

ROLLBACK TOSAVEPOINT隐式地销毁在命名的保存点之后建立的所有保存点。

parameter

WORK

TRANSACTION

Optional key words. They have no effect. savepoint_name

The name of asavepoint to roll back to.

Notes

Use releasesavepoint to destroy asavepoint without discarding the effects of commands executed after it wasestablished.

使用RELEASESAVEPOINT摧毁一个保存点不丢弃它建立后执行的命令的影响。

指定尚未建立一个保存点的名称是一个错误。

游标具有相对于保存点有点非事务性的行为。当保存点回滚时打开一个保存点内的任何游标将被关闭。如果先前打开的游标被保存点被后来回滚里面取命令的影响,光标位置保持在取指离开它指向的位置(也就是,FETCH不会回退)。关闭游标不是通过回滚,要么撤消。游标的执行导致交易中止放在一个不容执行状态,而事务可以用ROLLBACK TOSAVEPOINT恢复,不能再使用的光标。

示例

To undo theeffects of the commands executed after my_savepoint was established:

ROLLBACK TOSAVEPOINT my_savepoint;

Cursorpositions are not affected by a savepoint rollback:

BEGIN;

DECLARE foo CURSOR FOR SELECT 1 UNIONSELECT 2;

SAVEPOINT foo;

FETCH 1 FROMfoo; column

1

ROLLBACK TO SAVEPOINT foo;

FETCH 1 FROM foo;

column

2

COMMIT;

兼容性

SQL标准规定关键字SAVEPOINT是强制性的,但是GreenplumDatabase(和Oracle)允许省略它。 SQL只允许WORK,而不是TRANSACTION,作为ROLLBACK之后的噪音字。 此外,SQL还有一个可选的子句AND [NO] CHAIN,目前不支持Greenplum数据库。 否则,此命令符合SQL标准。

相关参考

BEGIN, COMM^IT, SAVEPOINT, RELEASESAVEPOINT, ROLLBACK