云数据库 GaussDB-SAVEPOINT:示例

时间:2023-11-01 16:22:03

示例

--创建一个新表。openGauss=# CREATE TABLE table1(a int);--开启事务。openGauss=# START TRANSACTION;--插入数据。openGauss=# INSERT INTO table1 VALUES (1);--建立保存点。openGauss=# SAVEPOINT my_savepoint;--插入数据。openGauss=# INSERT INTO table1 VALUES (2);--回滚保存点。openGauss=# ROLLBACK TO SAVEPOINT my_savepoint;--插入数据。openGauss=# INSERT INTO table1 VALUES (3);--提交事务。openGauss=# COMMIT;--查询表的内容,会同时看到1和3,不能看到2,因为2被回滚。openGauss=# SELECT * FROM table1;--删除表。openGauss=# DROP TABLE table1;--创建一个新表。openGauss=# CREATE TABLE table2(a int);--开启事务。openGauss=# START TRANSACTION;--插入数据。openGauss=# INSERT INTO table2 VALUES (3);--建立保存点。openGauss=# SAVEPOINT my_savepoint;--插入数据。openGauss=# INSERT INTO table2 VALUES (4);--回滚保存点。openGauss=# RELEASE SAVEPOINT my_savepoint;--提交事务。openGauss=# COMMIT;--查询表的内容,会同时看到3和4。openGauss=# SELECT * FROM table2;--删除表。openGauss=# DROP TABLE table2;
support.huaweicloud.com/centralized-devg-v2-opengauss/devg_03_0657.html