触发器抛出错误超出了最大存储过程,函数,触发器或视图嵌套级别

时间:2013-03-05 02:48:01

标签: sql sql-server triggers

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

触发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);

它抛出错误

  

* Msg 217,Level 16,State 1,Procedure tr_EligebilityCheckSRyear,Line 28
  超出最大存储过程,函数,触发器或视图嵌套级别(限制32)。*

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

1 个答案:

答案 0 :(得分:1)

触发器中的发出和UPDATE,触发器绑定的表将不会执行您期望的操作。仅仅因为更新代码在触发器代码中并不意味着更新语句不会导致触发器一遍又一遍地触发。如果有帮助,您可以获得UPDATED和DELETED的游标,表示已更新或删除的记录。