数据仓库服务 GAUSSDB(DWS)-SAVEPOINT:示例

时间:2024-10-16 16:27:27

示例

  • 建立一个保存点,然后撤销建立保存点后执行的所有命令的效果:
    1
    2
    3
    4
    5
    6
    7
    8
    START TRANSACTION;
    CREATE TABLE IF NOT EXISTS table1 (a int,b int);
    INSERT INTO table1 VALUES (1);
    SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (2);
    ROLLBACK TO SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (3);
    COMMIT;
    

    查询表的内容,会同时看到1和3,不能看到2,因为2被回滚。

  • 建立并随后销毁一个保存点:
    1
    2
    3
    4
    5
    6
    START TRANSACTION;
    INSERT INTO table1 VALUES (3);
    SAVEPOINT my_savepoint;
    INSERT INTO table1 VALUES (4);
    RELEASE SAVEPOINT my_savepoint;
    COMMIT;
    

    查询表的内容,会同时看到3和4。

support.huaweicloud.com/sqlreference-dws/dws_06_0263.html