SQL Clone
SQLServerCentral is supported by Redgate
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: 1845 | Views in the last 30 days: 11
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


Scripting options for Stored Procedures

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


Query Editor SSMS 2008 R2 Strange Script

Scripting Stored Procedures