首先,从SQLServer中的错误开始。SQL中的错误处理有点奇怪。误差水平同为16,但结果不同。
以下是一段引文片段:
以下是引用的内容:
如果@ @ error < & gt0
print '这没有输出'
go
raiserror(',16,3)
if @ @ error < & gt;0
print ' this output '
go
exec(' select * from a seen table ')
if @ @ error < & gt;0
print ' this output '
go
execsp _ execute sqln ' select * from a missing table '
if @ @ error < & gt;0
打印'此输出'
第二,导致孤立事件:
1、孤立交易的产生
以下是一段引文片段:
select@@trancount当前连接的活动事务数-当前连接的活动事务数为0
begin tran
select * from a except table
if @ @ error < & gt;0
begin
print '没有在这里运行!'
if @ @ trancount & lt;& gt0 roll back trans
end
commit ran
应该是rollback根本没有回滚。
2.利用现有手段解决孤立事务。
以下是一段引文片段:
以下是引用的内容:
Print @@trancount print '当前连接的活动事务数'-如果@ @ trancount < & gt0 roll back trans-在这里写只能保持隔离的事务,直到下一次调用您的过程为止
begin trans
select * from a seen table
if @ @ error < & gt;0
begin
print '没有在这里运行!'
if @ @ trancount & lt;& gt0 roll back tran
end
commit tran
-执行后可以看到当前连接的活动事务数为1,但重复执行不会累加
print @@trancount print '当前连接的活动事务数'
createtabletable 1(aint check(a & gt;00)]
Go
Set Xact _ abort on
Begin Tran
Insert Table 1 Values(10)
Print ' not executed here '
Commit Tran
Go Print ' ' Print ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' Print ' '
Set Xact _ abort off
Begin trans
Insert Table 1 Values(br/] 并且它还会生成一个独立的事务
setxact _ abort
begin Tran
insert a absent table values(10)
Print ' not executed here '
Commit ran
Go
Print ' ' Print ' = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ' Print '
setxact _ Print ' not executed here '
Commit Tran
Go
0回滚事务
关键词:SQL Server
优侠库网站每天提供最新最热门的安卓手机软件、游戏下载、分享热门手游资讯攻略教程、手机软件教程步骤,专注安卓手机游戏软件下载。本文链接:http://www.123down.cn/gonglue/227335.html