• I know this script and thread are a few years old, but this is a very helpful dependency finder for PROCS, so I wanted to share a slight change that one of my developers made to the original script. He is not a fan of temp tables, so he used a table variable instead. Here's the T-SQL:

    DECLARE @DepTree TABLE (ObjNum int identity(1,1) not null, Name varchar(1000), DependsOn varchar(1000), ObjectType char(2), DepLevel smallint)

    INSERT INTO @DepTree (Name, DependsOn, ObjectType, DepLevel)

    SELECT DependsOn = S.Name, S.Name, ObjectType = S.XType, DepLevel = 0

    FROM sys.sysobjects S

    WHERE S.Name = 'ENTER_YOUR_OBJECT_NAME_HERE'

    DECLARE @Name varchar(1000)

    DECLARE @DependsOn varchar(1000)

    DECLARE @DepLevel smallint

    DECLARE @ObjNum int

    SET @ObjNum = 1

    WHILE EXISTS(SELECT 1 FROM @DepTree WHERE ObjNum = @ObjNum)

    BEGIN

    SELECT @Name = Name, @DependsOn = DependsOn, @DepLevel = DepLevel FROM @DepTree WHERE ObjNum = @ObjNum

    -- this block finds objects that the current object of interest depends on (moving _down_ the dependency chain):

    IF @DepLevel >= 0

    INSERT INTO @DepTree (Name, DependsOn, ObjectType, DepLevel)

    SELECT DISTINCT S1.Name, DependsOn = S2.Name, ObjectType = S2.XType, DepLevel = @DepLevel + 1

    FROM sys.sysdepends DP

    JOIN sys.sysobjects S1 ON S1.ID = DP.ID

    JOIN sys.sysobjects S2 ON S2.ID = DP.DepID

    WHERE S1.Name = @DependsOn

    ORDER BY 1, 3, 2

    -- this block finds objects that depend on the current object of interest (moving _up_ the dependency chain):

    IF @DepLevel <= 0

    INSERT INTO @DepTree (Name, DependsOn, ObjectType, DepLevel)

    SELECT DISTINCT S2.Name, DependsOn = S1.Name, ObjectType = S2.XType, DepLevel = @DepLevel - 1

    FROM sys.sysdepends DP

    JOIN sys.sysobjects S1 ON S1.ID = DP.DepID

    JOIN sys.sysobjects S2 ON S2.ID = DP.ID

    WHERE S1.Name = @Name

    ORDER BY 1, 3, 2

    SET @ObjNum = @ObjNum + 1

    END

    SELECT * FROM @DepTree