SP and function dependencies

Finding dependencies in SPs is always pain. This SP scans the SP for calls to SPs, functions and other stuff (you can see it in the where clause "type in ('p','fn','if','x','ft','fs','pc')". It ignores commented out pieces of text. It uses a function fn_SplitBy included bellow, which splits the text (from syscomments) in char(10) delimited rows. The results are stored in a table "tree", which is created if it doesn't exist. To "pretty print" the dependency tree I'm using my previous published DBA_PrintTree stored proc. Actually, the published one is a bit different, so I'm including the modified one here.

while exists(select top 1 node from @stack) begin while exists (select treeid from #t where parenttreeid=@parent) begin select top 1 @bid=treeid,@bparent=parenttreeid,@nodename=nodename,@level=level from #t where parenttreeid=@parent order by nodename insert @t values(@bid,@bparent,@nodename,@level) print space(@level*5)+@nodename delete #t where treeid=@bid insert @stack values(@bid) set @parent=@bid end delete @stack where d in (select max(d) from @stack) select top 1 @parent=node from @stack order by d desc end

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.