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

时间:2018-01-05 19:44:23

标签: sql sql-server

我收到以下错误:

  

超出最大存储过程,函数,触发器或视图嵌套级别(限制32)。

我可以在其他帖子中看到它与你需要添加一个go有关。我不知道该怎么做,并注意到它的递归过程。任何想法如何解决这个问题?

ALTER PROCEDURE [dbo].[SetMigrate]
    (@DirId uniqueidentifier,
     @Source nvarchar(255),
     @Recursive bit)
AS
    DECLARE @IsRoot AS BIT

    SELECT @IsRoot = IsMigrationRoot 
    FROM directories 
    WHERE folderid = @DirId

    IF (@IsRoot = 1)
    BEGIN
        RETURN 
    END

    UPDATE directories  
    SET migrate = 1, [source] = @Source 
    WHERE folderid = @DirId

    IF (@Recursive = 0)
    BEGIN
        RETURN
    END

    DECLARE @parentid uniqueidentifier, @directoryid uniqueidentifier

    DECLARE Directories cursor local read_only for 
         SELECT FolderID, ParentFolderID 
         FROM directories 
         WHERE ParentFolderID = @DirId

    OPEN Directories

    FETCH NEXT FROM Directories INTO @directoryid, @parentid

    WHILE @@FETCH_STATUS = 0 
    BEGIN
        --print @Path
        EXEC SetMigrate @directoryid, @Source, @Recursive

        FETCH NEXT FROM Directories INTO @directoryid, @parentid
    END

    CLOSE Directories
    DEALLOCATE Directories
GO

1 个答案:

答案 0 :(得分:0)

首先删除if语句的开头和结尾。还要确保已更改数据库以允许recursive_triggers。