1

我有两个触发器,它们看起来几乎相同,但差异很小

触发器 1

create trigger tr_EligebilityCheckSRmonth
on dbo.Clients
after INSERT,UPDATE
as 

BEGIN
UPDATE Clients 
SET 
StatusID = 5
WHERE 
ClientID IN (Select ClientID
             from Clients c 
             join IncomeEligibility i 
                  on c.HshldSize = i.HshldSize
             where c.HshldSize= i.HshldSize 
                   and c.AnnualHshldIncome >= i.SeniorMo 
                   and StatusID in (1,2) 
                   and c.CategCode = 'SR' 
                   and MonthlyYearly ='month')
END

触发器 2

create trigger tr_EligebilityCheckSRyear
on dbo.Clients
after INSERT,UPDATE
as 

BEGIN
UPDATE Clients 
SET 
StatusID = 5
WHERE 
ClientID IN (Select ClientID
             from Clients c 
             join IncomeEligibility i 
                  on c.HshldSize = i.HshldSize
             where c.HshldSize= i.HshldSize 
                   and c.AnnualHshldIncome >= i.SeniorMo 
                   and StatusID in (1,2) 
                   and c.CategCode = 'SR' 
                   and MonthlyYearly ='year')
End

当我像这样提交插入 ststamnet

INSERT INTO Clients (ClientID, LastName, FirstName, MidInitial, DOB, Address, Address2, City, Zip, Phone, CategCode, StatusID, Hispanic, EthnCode, LangID, ClientProxy, Parent, HshldSize, AnnualHshldIncome, MonthlyYearly, PFDs, WIC, Medicaid, ATAP, FoodStamps, AgencyID, RoutID, DeliveryNotes, AppDate, CertifiedDate, Notes)
VALUES (13542,'Test','Test',null,'1982-10-20','P.O. Box 5',null,'TEST',99999,'(907) 111-1111','SR',1, 0, 'W',1, null, null,3,1000000,'year',0,0, 1,  0,1,45, null,null,'2011-04-27', null,null);

它抛出错误

*消息 217,级别 16,状态 1,过程 tr_EligebilityCheckSRyear,第 28 行 超出
最大存储过程、函数、触发器或视图嵌套级别(限制 32)。*

我试图将它们组合在一个触发器中并使用 IF else 但没有任何疑问。如果我在系统中只有一个,它可以工作,但是当我有两个时,它会抛出错误。如何解决这个问题?我在这里查看其他帖子,但找不到任何有用的东西。

4

1 回答 1

1

在触发器中发布和更新,对于触发器绑定到的表,不会像你期望的那样做。仅仅因为更新代码在触发器代码中并不意味着更新语句不会导致触发器一遍又一遍地触发。如果有帮助,您可以获得 UPDATED 和 DELETED 游标,表示已更新或删除的记录。

于 2013-03-05T03:53:29.493 回答