Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Stored Procedure Call Hierarchy

By cneuhold,

Easily extractss the complete stored procedure call hierarchy from "sysdepends" table of SQL Server and represent it in a pseudo-graphical tree-view.

The script uses a temporary table (automatically created/dropped) to hold children and parents of relationships. For representing the call hierarchy the table contains a level field (depth) and a field containing the "enumerated path" (using the procedure's id) denoting the hierarchical position of the respective child procedure (similar to chapter-numbering in a book).

First of all the script inserts all top-level procedures into the table, then all parent-child relations (both extracted from "sysdepends" table). A loop calculates the "enumerated path". It uses as many iterations as necessary to process all relationships in the table.

If there are cyclic dependencies the script will also detect that (number of dependencies that cannot be calculated does not change between two iterations). The two select statements at the end output the result.

Script has been successfully tested in larger environments (2K stored procedures) showing quite fine performance. Analysis capabilities are powerful (eg. selecting subtrees is not an issue, give it a try).

Total article views: 1801 | Views in the last 30 days: 15
Related Articles

Scripting Stored Procedures

Scripting Stored Procedures


Generate Drop / Create Script for views, stored Procedures

This Script generates drop and create scripts for views or stored procedures.


Script Search

Script to save stored procedures


Query Editor SSMS 2008 R2 Strange Script

Scripting Stored Procedures


Scripting options for Stored Procedures

Scripting the IF EXISTS portion of a DROP statement for Stored Procedures


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones