【发布时间】:2020-05-17 09:40:05
【问题描述】:
我有这个带有事务和 try/catch 的语句块:
begin try
begin transaction;
insert ....
update ....
delete ....
commit transaction;
end try
begin catch
if (@@trancount > 0)
rollback transaction;
throw;
end catch;
我在这里使用@@trancount,但没有完全理解会发生什么。
为什么在这种情况下@@trancount 会为零?
【问题讨论】:
-
一个例子是由
INSERT调用的触发器,它回滚事务并抛出catch捕获的错误
标签: sql-server transactions try-catch