Link to home
Start Free TrialLog in
Avatar of SigmundFraud
SigmundFraud

asked on

Tracking what tables appear in which queries

Hi

I have tables A,B,C that need to be renamed. However they are referenced in several queries and i would need some code that would list what queries these tables appear in.

Many thanks!
ASKER CERTIFIED SOLUTION
Avatar of wittyslogan
wittyslogan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SigmundFraud
SigmundFraud

ASKER

Thanks for the swift response.

They're in some sp's but mainly in views.
Tables can be referenced directly by program code. It's hard to know what queries can be run by the various programs that connect to your database. However, if you only refer to Stored Procedures, Functions, and Views, then

select distinct object_name(id) from syscomments where text like '%tbl%'
order by 1
It's possible that procedures are created encrypted, so this technique will not work. In that case, you will need to find a decrypter (sql2000 ones are easily found) and actually decrypt each and every proc and drop/create them unencrypted before  syscomments  will reveal anything useful.
views should be accesible using the code as well.  we are referencing the sysobjects table
Excellent solution, thanks Witty.