[點(diǎn)晴永久免費(fèi)OA]SET XACT_ABORT各種用法及顯示結(jié)果
:SET XACT_ABORT各種用法及顯示結(jié)果 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 -- 事務(wù)回滾 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 -- 事務(wù)在錯(cuò)誤行終止,錯(cuò)誤行回滾,錯(cuò)誤行之前的不回滾 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 編輯過(guò) |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |