保存

保存 - “在当前事务中定义新的保存点

句法

保存 savepoint_name

描述

保存 在当前事务中建立一个新的保存点。
保存点在建立保存点之后执行的所有命令的事务中的一个点识别,从而将事务状态恢复到原始状态。可以在事务中定义多个保存点。
Use 犯罪 to release all savepoints and commit all database changes for the current transaction (See 犯罪)。
Use 回滚 TO SAVEPOINT to rollback to a previously specific savepoint within the current transaction (See 回滚)。 Use 回滚 to rollback all changes for the current transaction, regardless of savepoints in the current transaction.
Use 发布保存点 to destroy a savepoint.

AUTOCOMMIT must be OFF to enable transaction savepoints.

参数

savepoint_name

名称给出了新的保存点。

例子

Example 1: Error using 保存 and 回滚 TO SAVEPOINT
表演 AUTOCOMMIT
    Autocommit is on
DROP TABLE testtable IF EXISTS;
CREATE TABLE testtable (column1 STRING);
 INTO testtable VALUES ('Insert Before Savepoint first');
保存 first;
 INTO testtable VALUES ('Insert After Savepoint first');
选择 * FROM testtable;
            COLUMN1
 -----------------------------
 Insert Before Savepoint first
 Insert After Savepoint first

回滚 TO 保存 first;
    savepoint "FIRST" is not defined
示例2:在当前事务中定义一个或多个保存点。
 AUTOCOMMIT off;
CREATE TABLE testtable (column1 STRING);
 INTO testtable VALUES ('Insert Before Savepoint first');

保存 first;
 INTO testtable VALUES ('Insert After Savepoint first');
选择 * FROM testtable;
            COLUMN1
 -----------------------------
 Insert Before Savepoint first
 Insert After Savepoint first

回滚 TO 保存 first;
选择 * FROM testtable;
            COLUMN1
 -----------------------------
 Insert Before Savepoint first


保存 second;
 INTO testtable VALUES('Insert After Savepoint second');
选择 * FROM testtable;
            COLUMN1
 -----------------------------
 Insert Before Savepoint first
 Insert After Savepoint second

RELEASE 保存 second;
犯罪;
选择 * FROM testtable;
            COLUMN1
 -----------------------------
 Insert Before Savepoint first
 Insert After Savepoint second