[點晴永久免費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 編輯過 |
關鍵字查詢
相關文章
正在查詢... |