sql事物和try catch

 1 begin transaction tr
 2    declare @error int;
 3    set @error=0;
 4    select * from Car_Brand
 5    set @error=@error+@@ERROR
 6    select 1/0
 7    set @error=@error+@@ERROR
 8    select * from AREA
 9    set @error=@error+@@ERROR
10    print 'i have executed!'
11    set @error=@error+@@ERROR
12    
13    print '@@error:'+cast(@error as varchar(50))
14    if(@error<>0)
15      begin
16       print 'executed failed';
17       rollback transaction tr
18      end
19    else    
20      begin
21       print 'executed success';
22       commit transaction tr
23      end
 1 begin  try
 2 begin transaction tr
 3 
 4    select * from Car_Brand
 5    update car_log set [reason]='ceshiceshiceshi' where [modelid]=557;
 6    select 1/0
 7    print 'i have executed!'
 8    select * from AREA
 9    
10    
11    print 'executed success';
12    commit transaction tr
13    
14    
15 end try
16 begin catch
17   print 'executed failed';
18   rollback transaction tr
19 end catch

 

转载于:https://www.cnblogs.com/zhipeng007/p/10569312.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值