关于触发器中事务回滚 求助

heyixiang 2005-03-28 11:15:56
ALTER Trigger trCheckResearchStatus_2
On dbo.research
For Insert,Update
As
Begin transaction
Declare curGetNewID cursor For
Select id,restriction,voteinterval,timeunit from Inserted
Declare @intID int,@inyRestriction tinyint,@intVoteinterval int,@inyTimeunit tinyint
Open curGetNewID
Fetch Next from curGetNewID Into @intID,@inyRestriction,@intVoteinterval,@inyTimeunit
While @@Fetch_Status=0
Begin
If not Exists (Select * From question where reid=@intID)
Update research set status=0 where id=@intID
if @intVoteinterval=0 and @inyRestriction=2
rollback transaction
Fetch Next From curGetNewID into @intID,@inyRestriction,@intVoteinterval,@inyTimeunit
End
Close curGetNewID
Deallocate curGetNewID
Commit transaction


提示 Cimmit transaction请求没有对应的Begin transaction

怎么解决?
...全文
192 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
heyixiang 2005-03-31
  • 打赏
  • 举报
回复
没人解疑啊
heyixiang 2005-03-28
  • 打赏
  • 举报
回复
没有人帮忙啊?
heyixiang 2005-03-28
  • 打赏
  • 举报
回复
rollback transaction 是不是不能放到游标中?

jinjazz(近身剪*10年磨一贴) 你给我的参考不能解决我的问题
jinjazz 2005-03-28
  • 打赏
  • 举报
回复
参考
CREATE TRIGGER trig_customerinfo_deleteupdate
ON customerinfo
FOR UPDATE
AS
If UPDATE(customerno)
BEGIN
select orderid from orderinfo where orderinfo.customerno = (select customerno from deleted)
if @@rowcount > 0
begin
RAISERROR ('不能修改编号,有相应的记录在订单表上', 16, 1)
ROLLBACK TRANSACTION
end
END
GO
heyixiang 2005-03-28
  • 打赏
  • 举报
回复
顶起
是是非非 2005-03-28
  • 打赏
  • 举报
回复
好像在那个文章里面看到过关于触发器使用事务的
等我找找
heyixiang 2005-03-28
  • 打赏
  • 举报
回复
cjxcjx(ew)还是没用


提示 Cimmit transaction请求没有对应的Begin transaction

cjxcjx 2005-03-28
  • 打赏
  • 举报
回复

begin tran
begin
end
commi
用这总形式

34,575

社区成员

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

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