ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION

glassy2000 2010-10-13 08:02:54
这是我的存储过程,编译通过:
ALTER PROCEDURE [dbo].[st_dele_whole_sales]
@id int,
@execute int output
AS
BEGIN
begin transaction
begin try
update tb_sales set active='L' where id=@id
set @execute=1

commit transaction
end try
begin catch
set @execute=0
rollback transaction
end catch
END

但执行时却出错:
st_dele_whole_sales 13194,-1

错误提示:
消息 3903,级别 16,状态 1,过程 st_dele_whole_sales,第 21 行
ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。

没发现语句有错呀,是哪不对呀,请大家指教!!
...全文
584 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
颠簸在路上 2011-05-31
  • 打赏
  • 举报
回复
commit transaction 已经提交了上面的transaction
下面的 rollback transaction 已经没有事务回滚了
abuying 2010-10-13
  • 打赏
  • 举报
回复
ALTER PROCEDURE [dbo].[st_dele_whole_sales]
@id int,
@execute int output
AS
BEGIN

begin transaction
update tb_sales set active='L' where id=@id
set @execute=1
begin try --把transaction提前到try前
commit transaction
end try
begin catch
set @execute=0
rollback transaction
end catch
END
SQLCenter 2010-10-13
  • 打赏
  • 举报
回复
ALTER PROCEDURE [dbo].[st_dele_whole_sales] 
@id int,
@execute int output
AS
BEGIN
begin try
begin transaction
update tb_sales set active='L' where id=@id
set @execute=1
commit transaction
end try
begin catch
set @execute=0
rollback transaction
end catch
END

34,838

社区成员

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

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