[点晴永久免费OA]SET XACT_ABORT各种用法及显示结果
当前位置:点晴教程→点晴OA办公管理信息系统
→『 经验分享&问题答疑 』
:SET XACT_ABORT各种用法及显示结果 create database demo use demo CREATE TABLE student ( stuid int NOT NULL PRIMARY KEY , stuname varchar ( 50 ) ) CREATE TABLE score ( stuid int NOT NULL REFERENCES student(stuid), score int ) GO INSERT INTO student VALUES ( 101 , ' zhangsan ' ) INSERT INTO student VALUES ( 102 , ' wangwu ' ) INSERT INTO student VALUES ( 103 , ' lishi ' ) INSERT INTO student VALUES ( 104 , ' maliu ' ) GO use demo -- Invoking a run-time error SET XACT_ABORT OFF BEGIN TRAN INSERT INTO score VALUES ( 101 , 90 ) INSERT INTO score VALUES ( 102 , 78 ) INSERT INTO score VALUES ( 107 , 76 ) /**/ /* Foreign Key Error */ INSERT INTO score VALUES ( 103 , 81 ) INSERT INTO score VALUES ( 104 , 65 ) COMMIT TRAN go -- select * from score 101 90 102 78 103 81 104 65 use demo -- 事务回滚 SET XACT_ABORT on BEGIN TRAN INSERT INTO score VALUES ( 101 , 90 ) INSERT INTO score VALUES ( 102 , 78 ) INSERT INTO score VALUES ( 107 , 76 ) /**/ /* Foreign Key Error */ INSERT INTO score VALUES ( 103 , 81 ) INSERT INTO score VALUES ( 104 , 65 ) COMMIT TRAN go -- select * from score use demo -- 事务在错误行终止,错误行回滚,错误行之前的不回滚 SET XACT_ABORT on BEGIN INSERT INTO score VALUES ( 101 , 90 ) INSERT INTO score VALUES ( 102 , 78 ) INSERT INTO score VALUES ( 107 , 76 ) /**/ /* Foreign Key Error */ INSERT INTO score VALUES ( 103 , 81 ) INSERT INTO score VALUES ( 104 , 65 ) END go -- select * from score 101 90 102 78 该文章在 2024/6/17 15:54:55 编辑过 |
关键字查询
相关文章
正在查询... |