触发嵌套级别超出?

时间:2012-03-01 20:21:26

标签: sql-server-2008

触发此触发器时,该触发器包含在下面的代码块中

alter TRIGGER [dbo].[locations_update_geometry_After]
ON  dbo.TBL_LOCATIONS   
for update   
AS   
  INSERT dbo.TBL_LOCATIONS(SHAPE, X_Coord, Y_Coord,objectid) 
  SELECT a.Shape, a.X_Coord, a.Y_Coord, a.objectid
  FROM  
  (  
    SELECT  
      SHAPE = CASE WHEN SHAPE IS NOT NULL   
        THEN SHAPE ELSE Geometry::STPointFromText('POINT('  
          + CAST(X_Coord AS VARCHAR(20)) + ' '   
          + CAST(Y_Coord AS VARCHAR(20)) + ')', 26917) END,  
      X_Coord = CASE WHEN SHAPE IS NULL THEN X_Coord ELSE SHAPE.STX END,  
      Y_Coord = CASE WHEN SHAPE IS NULL THEN Y_Coord ELSE SHAPE.STY END,  
      objectid  
     FROM inserted  
  ) AS a

我收到以下错误消息:

  

无法保存修改。基础DBMS错误[Microsoft SQL Server   Native Client 10:最大存储过程,函数,触发器或视图   超出嵌套级别(限制32)。

我没有32个与此表关联的内容。任何想法?

2 个答案:

答案 0 :(得分:4)

是的,触发器在执行消息之前执行了32次;为了停止这样做,使用这个

IF ((
SELECT TRIGGER_NESTLEVEL()) > 1 )
RETURN

答案 1 :(得分:0)

你可能应该看看“INSTEAD OF UPDATE”

http://technet.microsoft.com/en-us/library/ms188601(v=sql.105).aspx