SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Find Stored Procedures and Functions That Reference Certain Tables


Find Stored Procedures and Functions That Reference Certain Tables

Author
Message
hakim.ali
hakim.ali
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 1064
Comments posted to this topic are about the item Find Stored Procedures and Functions That Reference Certain Tables

Hakim Ali
www.sqlzen.com
sdorris 90134
sdorris 90134
Mr or Mrs. 500
Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)Mr or Mrs. 500 (591 reputation)

Group: General Forum Members
Points: 591 Visits: 619
Hakim - this script is excellent. It will help me to locate "no longer needed" procedures in my development process. Thanks for posting!
Megistal
Megistal
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2408 Visits: 2555
This is nice, helpful and I hope to see more from you but the script take for granted that the searched object is unique amongst all other objects name even part of it.

For instance looking for Table1 when Table123 is solely used inside an object will shows that object as if Table1 used it instead which is not the case.
arthur.teter
arthur.teter
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1211 Visits: 126
Hakim,
This is good.
Sometime in the past I read that you were supposed to use information_schema instead of the sys tables for this type of thing, and had been using them to find deprecated column references during upgrades. Compared my script with yours, and found that yours found references that I had missed. I never noticed before today that the corresponding definition fields in the information_schema views are limited to the first 4000 characters of the script.
John Mitchell-245523
John Mitchell-245523
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24088 Visits: 16472
arthur.teter (8/2/2013)
I never noticed before today that the corresponding definition fields in the information_schema views are limited to the first 4000 characters of the script.

Same with syscomments, which you should avoid using because it's only there for backward compatibility and could be deprecated in a future release. Not only that, sys.sql_modules has the whole definition on one row, so you won't miss out if your search string straddles the 4000-character boundary.

John
hakim.ali
hakim.ali
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 1064
sdorris 90134 (8/2/2013)
Hakim - this script is excellent. It will help me to locate "no longer needed" procedures in my development process. Thanks for posting!


Thank you.

Hakim Ali
www.sqlzen.com
hakim.ali
hakim.ali
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 1064
Megistal (8/2/2013)
This is nice, helpful and I hope to see more from you but the script take for granted that the searched object is unique amongst all other objects name even part of it.

For instance looking for Table1 when Table123 is solely used inside an object will shows that object as if Table1 used it instead which is not the case.


Thanks for pointing that out. I hadn't considered this scenario, maybe because I haven't encountered a situation with objects named that way. I guess I could code for it by checking the charindex of, say Table1, and comparing it to the charindex of Table123. If they have the same value, I know I have Table123 and not table 1.

Hakim Ali
www.sqlzen.com
hakim.ali
hakim.ali
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 1064
arthur.teter (8/2/2013)
...Sometime in the past I read that you were supposed to use information_schema instead of the sys tables for this type of thing...


I generally prefer using information_schema too, as that is the ansi standard and will generally work on all relational databases and is more resistant to being obsoleted. I make exceptions when using sys.* results in easier code. And not all database objects are available through information_schema, sometimes I have to use sys.*.

Hakim Ali
www.sqlzen.com
hakim.ali
hakim.ali
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1054 Visits: 1064
John Mitchell-245523 (8/2/2013)
...sys.sql_modules has the whole definition on one row...


Thanks for the tip, will check out sys.sql_modules.

Hakim Ali
www.sqlzen.com
sequelgarrett
sequelgarrett
SSC Veteran
SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)SSC Veteran (293 reputation)

Group: General Forum Members
Points: 293 Visits: 1235
<edit>
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search