Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2008

SQL Server Scripts: Get All Nested Stored Procedures List (Procedures with Dependent Procedures)

0.00/5 (No votes)
1 Nov 2012CPOL 35.5K  
A stored procedure can be called from another stored procedure as nested stored procedure. How to get a list of these stored procedures with their nested one

Introduction

A stored procedure can be called from another stored procedure as a nested stored procedure. Recently on production server, we were asked for all stored procedures in which other stored procedures are called as nested. Here is a simple script.

Using the Code

SQL
SELECT  * FROM (SELECT  NAME AS ProcedureName, SUBSTRING(( SELECT  ', ' + OBJDEP.NAME
FROM    sysdepends
        INNER JOIN sys.objects OBJ ON sysdepends.ID = OBJ.OBJECT_ID
        INNER JOIN sys.objects OBJDEP ON sysdepends.DEPID = OBJDEP.OBJECT_ID
WHERE obj.type = 'P'
AND Objdep.type = 'P'
AND sysdepends.id = procs.object_id
ORDER BY OBJ.name

FOR
XML PATH('')
), 2, 8000) AS NestedProcedures
FROM sys.procedures  procs )InnerTab
WHERE NestedProcedures IS NOT NULL

Image 1

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)