关于触发器问题??好久没来了先奉上100分

IDWB 2006-01-23 11:19:31
我想让这个触发器循环触发,中间注解地方就是我设想的再次触发地方
但是事实不会第2次触发请问高手原因,如何修改


CREATE TRIGGER trg_upd_PJDXB_info ON dbo.PJDXB
FOR update
AS
SET NOCOUNT ON
declare @DQKC real ,
@PJLB tinyint
set @PJLB=(Select PJLB from PJDZB,inserted where PJDZB.PJDH=inserted.PJDH)
if (not update(DQKC)) and (not update(DQZT) and (not update(KCDJ)))
begin
if @PJLB<10
begin
--------------------再次修改此表触发本修改触发器
update PJDXB
set DQKC=PJDXB.DQKC+inserted.SL-deleted.SL
from inserted,deleted
where PJDXB.ID=inserted.ID
--------------------想转到下面的一个注解
Update shangpin_info
Set ZXJHJ=inserted.DJ
From inserted
Where shangpin_info.SPID=inserted.SPID
End
Else
Begin
Update shangpin_info
Set ZXXSJ=inserted.DJ
From inserted
Where shangpin_info.SPID=inserted.SPID
end
end
else
begin
------------------------再次触发从这里开始
if update(DQKC)
begin
set @DQKC=(select DQKC from inserted)
if @DQKC=0
begin
update PJDXB
set DQZT=22
from inserted
where PJDXB.ID=inserted.ID
end
if (select DQZT from deleted)=22 and @DQKC>0
begin
update PJDXB
set DQZT=21
from inserted
where PJDXB.ID=inserted.ID
end
end
if (not update(DQZT))
begin
If not exists(select 1 from DQKCJL,inserted
where DQKCJL.SPID=inserted.SPID and
DQKCJL.CKH=inserted.CKH)
begin
Insert into DQKCJL
Select CKH,SPID,SL,DJ*SL from inserted
end
else
begin
Update DQKCJL
Set KCSL=KCSL+inserted.DQKC,
KCJE=KCJE+inserted.DQKC*inserted.KCDJ
From inserted
Where DQKCJL.SPID=inserted.SPID and
DQKCJL.CKH=inserted.CKH
Update DQKCJL
Set KCSL=KCSL-isnull(deleted.DQKC,0),
KCJE=KCJE-isnull(deleted.DQKC,0)*isnull(deleted.KCDJ,0)
From deleted
Where DQKCJL.SPID=deleted.SPID and
DQKCJL.CKH=deleted.CKH
end
end
end
SET NOCOUNT OFF












...全文
93 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
IDWB 2006-01-23
  • 打赏
  • 举报
回复
可以触发了,太感谢了
IDWB 2006-01-23
  • 打赏
  • 举报
回复
非常感谢,我先去试试
子陌红尘 2006-01-23
  • 打赏
  • 举报
回复
触发器不会以递归方式自行调用,除非设置了 RECURSIVE_TRIGGERS 数据库选项。

RECURSIVE_TRIGGERS:当设置为 ON 时,触发器可以递归激发。当设置为 OFF(默认)时,触发器不能递归激发。

说明 当 RECURSIVE_TRIGGERS 为 OFF 时,只禁止直接递归。若要禁用间接递归,还必须将 nested triggers 服务器选项设置为 0。
IDWB 2006-01-23
  • 打赏
  • 举报
回复
请问如何才能递归,实现我所设计的思想
子陌红尘 2006-01-23
  • 打赏
  • 举报
回复
这个触发器不会被递归调用,自然不存在二次乃至三次触发的情况。

34,593

社区成员

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

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