作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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
----------
Uncommittable transaction is detected at the end of the batch. The transaction is rolled back.
begin tran one
begin tran two
rollback tran two
Cannot roll back two. No transaction or savepoint of that name was found.
最佳答案
运算符(operator)回滚回滚所有事务,对于仅回滚第二个循环,您必须使用保存点:
begin tran one
-- do some inserts in others tables
--start loop
save tran two -- begin tran two
--do something
begin try
update product set id = 1 --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
create table product (id int)
GO
create trigger product_trigger on product for update
as
set xact_abort off
if (select count(*) from inserted i join product p on i.id=p.id)=0 begin
if (@@trancount>0) begin
/* rollback */
raiserror('product does not exist', 16, 1)
end
end
关于sql - 无法回滚子事务。未找到该名称的事务或保存点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19260055/
我是一名优秀的程序员,十分优秀!