begin transacation
declare @sumErrors int=0
//执行sql操作
----------
set @sumErrors=@sumErrors+@@error
----------
set @sumErrors=@sumErrors+@@error
if @sumErrors=0
begion
--表示没出错
commit transacation --提交事务
end
else
begion
rollback
列
begin transaction
declare @sumError int;
set @sumError=0;
select * from ApplyKey
set @sumError=@sumError+@@error
select * from Attachment
set @sumError=@sumError+@@error
if @sumError = 0
begin
print '成功'
commit transaction
end
else
begin
rollback
end
end
本文详细介绍了使用SQL事务进行数据库操作的方法,以及如何通过累计错误计数来判断事务是否应该提交或回滚。通过示例代码,展示了如何在SQL中声明变量、执行操作并根据错误情况决定事务的最终状态。
20万+

被折叠的 条评论
为什么被折叠?



