事务嵌套问题,回滚外层事务

diffmaker 2009-10-16 11:32:50
看了相关的帖子,还是没有搞明白

我有一个表t_test_A,只有一个int字段,不允许空

存储过程如下
create procedure sp_test_A(
@id int=null
)
as
if @@trancount=0
begin transaction A
else
save transaction A
insert t_test_A values(@id)
if @@error<>0 goto transA
insert t_test_A values(888)
if @@error<>0 goto transA
if @@error<>0
begin
transA:
rollback tran A
end
else
commit tran A
go
create procedure sp_test_B as
begin tran B
insert t_test_A values(666)
if @@error<>0 goto transB
execute sp_test_A
if @@error<>0 goto transB
if @@error<>0
begin
transB:
rollback tran B
end
else
commit tran B
go


在存储过程sp_test_B中,调用了sp_test_A,由于表中不允许插入空值,sp_test_A出错,但是sp_test_B并没有回滚,仍然在表中插入了数666,我该怎么做?
...全文
450 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ruby512 2009-10-16
  • 打赏
  • 举报
回复
execute sp_test_A
执行是成功的。就不会执行事务B的回滚
sp_test_A 只能执行事务A的回滚
diffmaker 2009-10-16
  • 打赏
  • 举报
回复
人呢?

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧