【发布时间】:2013-10-08 23:02:46
【问题描述】:
我在 sql 中有一个循环,它会做一些事情
begin tran one
do some inserts in others tables
--start loop
begin tran two
--do something
begin try
--if something fail then a trigger does rollback and this return a error (and this goes to catch), then don't i need do the rollbak in catch? this could not be dissable because this is working on production
--something finished ok
commit tran two
end try
begin catch
rollback tran two
end catch
--finished loop
commit
----------
我收到了这个错误
在批处理结束时检测到不可提交的事务。这 事务被回滚。
begin tran one
begin tran two
rollback tran two
做这个代码我得到这个:
不能回滚两个。未找到该名称的事务或保存点。
我只希望子查询回滚第二个循环并继续处理其他记录。
【问题讨论】:
-
查看这个问题:stackoverflow.com/questions/4614942/… 特别注意置顶答案中的链接。
-
SQL server 中本质上没有嵌套事务这种东西。
标签: sql tsql loops transactions