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的例子
作者:过错
出处:http://www.cnblogs.com/wang2650/
关于作者:net开发做的久而已。十余年时光虚度!
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题,可以邮件:wang2650@163.com
联系我,非常感谢。