• CUBRID学习笔记17 事务的回滚


    语法:ROLLBACK [ WORK ]

    下面的语句会报错

    ALTER TABLE code DROP s_name;

    INSERT INTO code (s_name, f_name) VALUES ('D','Diamond');

     

    ERROR: s_name is not defined.

    回滚 修复破损的伤口

    ROLLBACK WORK;

    再来

    ALTER TABLE code drop s_name;

    INSERT INTO code (f_name) VALUES ('Diamond');

     

    COMMIT WORK;

     

    部分回滚

    可以设置标记,使回滚到指定的标记位置

     

    方法1 SAVEPOINT mark;

    mark:

    _ a SQL identifier

    _ a host variable (starting with :)

     

    方法2 

     

    ROLLBACK [ WORK ] [ TO [ SAVEPOINT ] mark ] [ ; ]

    mark:

    _ a SQL identifier

    _ a host variable (starting with :)

     

    例子

    首先设置两个回滚的标记 sp1 和sp2

    CREATE TABLE athlete2 (name VARCHAR(40), gender CHAR(1), nation_code CHAR(3), event VARCHAR(30));

    INSERT INTO athlete2(name, gender, nation_code, event)

    VALUES ('Lim Kye-Sook', 'W', 'KOR', 'Hockey');

    SAVEPOINT SP1;

     

    SELECT * from athlete2;

    INSERT INTO athlete2(name, gender, nation_code, event)

    VALUES ('Lim Jin-Suk', 'M', 'KOR', 'Handball');

     

    SELECT * FROM athlete2;

    SAVEPOINT SP2;

     

    RENAME TABLE athlete2 AS sportsman;

    SELECT * FROM sportsman;

    ROLLBACK WORK TO SP2;

    上面的重命名表的操作将被回滚

     

     

    SELECT * FROM athlete2;

    DELETE FROM athlete2 WHERE name = 'Lim Jin-Suk';

    SELECT * FROM athlete2;

    ROLLBACK WORK TO SP2;

    上面的删除也不会执行,会被回滚

     

     

    SELECT * FROM athlete2;

    ROLLBACK WORK TO SP1;

    SELECT * FROM athlete2;

    COMMIT WORK;

    这个是回滚到sp1的例子

     

     

     

     

     

  • 相关阅读:
    Joshua Bloch错了? ——适当改变你的Builder模式实现
    集成基于OAuth协议的单点登陆
    集成基于CAS协议的单点登陆
    数据库设计中的Soft Delete模式
    完成C++不能做到的事
    ExtJS in Review
    DTO – 服务实现中的核心数据
    保存好你的密码 —— 从芝麻金融被攻破说起
    WPF
    C# 反编译防范
  • 原文地址:https://www.cnblogs.com/wang2650/p/5284080.html
Copyright © 2020-2023  润新知