Home > A to Z SQL Command, Link, Microsoft SQL Server, MSBI, Query,, Script, SQL Mentalist, SQL Query, SQL Server, SQL Tricks, Technology,, TSQL, Vishal Pawar > BI SQL # 114 : SQL Server DBA Scripts : Find all nested stored procedure – Stored procedure called in another procedure

BI SQL # 114 : SQL Server DBA Scripts : Find all nested stored procedure – Stored procedure called in another procedure

Hi Geeks,

In this article we are going to cover How to Find all nested stored procedure – Stored procedure called in another procedure.

 

In this post we are going to discuss following points:

  • Problem Statement of SQL Script:
  • Description of SQL Script:
  • SQL Script Output Column
  • SQL Script Code
  • SQL Script Output Screenshot
  • User Level to execute

 

 

Problem Statement of SQL Script:

How to find which stored procedure had been call in side which stored procedure?

What are relationships of stored procedure with each other?

Description of SQL Script:

This script will display relationships of stored procedure with each other.

A stored procedure can be called from another stored procedure as nested stored procedure. Recently on production server, we were asked for all stored procedures in which other stored procedures are called as nested. Get All Nested Stored Procedures List (Procedures with dependent Procedures)

SQL Script Output Column

image

SQL Script Code

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

SQL Script Output Screenshot

(Exceled and SQL Output)

Using this Simple test Script

image

    CREATE PROC IamInsideProc
    AS
    SELECT 'IamInsideProc'
    
    CREATE PROC IamMasterSP
    AS
    SELECT 'Now Calling Proc - IamInsideProc'
    
    EXEC IamInsideProc
    
    EXEC dbo.IamMasterSP

Output will be

image

User Level to execute

200

 

    Hope you will like How to Find all nested stored procedure – Stored procedure called in another procedure.

    If you really like reading my blog and understood at least few thing then please don’t forget to subscribe my blog.

If you want daily link and analysis or interesting link go to following website which will give @ your inbox please subscribe our following link resource blog :

Link Resource Website

For More information related to BI World visit my Mentalist Blog

SQL Server Mentalist >> SQL Learning Blog

Business Intelligence Mentalist >> BI World

Infographic Mentalist >> Image worth explaining thousand Words

Microsoft Mentalist >> MVC,ASP.NET, WCF & LinQ

DBA Mentalist >>Advance SQL Server Blog

Microsoft BI Mentalist >> MS BI Development Update

Connect With me on

| FaceBook |Twitter | linkedIn| Google+ | WordPress | RSS |

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: