普通sql事务: begin transaction tr declare @error int; set @error=0; select * from Car_Brand
begin transaction tr
declare @error int;
set @error=0;
select * from Car_Brand
set @error=@error+@@ERROR
select 1/0
set @error=@error+@@ERROR
select * from AREA
set @error=@error+@@ERROR
print 'i have executed!'
set @error=@error+@@ERROR
print '@@error:'+cast(@error as varchar(50))
if(@error<>0)
begin
print 'executed failed';
rollback transaction tr
end
else
begin
print 'executed success';
commit transaction tr
end
begin try
begin transaction tr
select * from Car_Brand
update car_log set [reason]='ceshiceshiceshi' where [modelid]=557;
select 1/0
print 'i have executed!'
select * from AREA
print 'executed success';
commit transaction tr
end try
begin catch
print 'executed failed';
rollback transaction tr
end catch
--结束END--
本文标题: SQL语句中事务与try catch使用
本文链接: https://www.lsjlt.com/news/40912.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
2024-04-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0