September 26, 2008 at 7:19 am
Is there any way to find all the tables referenced in all stored procedures in a database? I have come across code to pick the tables out of a single stored procedure, but I need a list for the whole db.
Thanks for any help with this.
Andy
September 26, 2008 at 8:08 am
From SQL Server itself, the sysdepends table is the only way that I know of, but it is unreliable.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
September 26, 2008 at 8:11 am
I read that if the database is refreshed then it should be fairly accurate. Would you agree with that?
September 26, 2008 at 8:23 am
That is what I do, but I have heard some say that that does not always work either, and I have definitely seen it miss some stuff.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
September 26, 2008 at 8:25 am
You should also be aware that none of this works on procedures that use Dynamic SQL.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
September 26, 2008 at 9:25 am
You might want to try:
SELECT * FROM sys.sql_modules WHERE Definition LIKE '%tablename%' OR Definition LIKE '%tablename%'
Now this could get to be tedious what with adding the OR clause so as to include all the table names in your DB.
September 26, 2008 at 10:16 am
And this is unreliable also.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply