1、回滚语句1:
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
2、回滚语句2:
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
结果2:事务终止并全部回滚,结果为空。
–select * from score
3、回滚语句3:
事务在错误行终止,错误行回滚,错误行之前的不回滚
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
- 结果3:出现这种是因为系统把每个insert语句都看成是单独的事务,所以错误行以前的是不回滚的。
复制代码 –select * from score
101 90
102 78
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |