Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 VIEW - TableReferences

Author  Topic 

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2002-02-21 : 16:12:33
CREATE VIEW TableReferences AS
SELECT TOP 100 PERCENT
t.TABLE_NAME,
OBJECT_NAME(c.id) AS [OBJECT_NAME],
COUNT(*) [MATCHES]
FROM INFORMATION_SCHEMA.TABLES t,
syscomments c
WHERE t.TABLE_TYPE = 'BASE TABLE'
AND c.text LIKE '%' + t.TABLE_NAME + '%'
GROUP BY t.TABLE_NAME,
c.id
ORDER BY t.TABLE_NAME, [MATCHES] DESC
GO

Sample Usage:
SELECT * FROM TableReferences WHERE TABLE_NAME = 'MyTable'


Edited by - onamuji on 02/21/2002 16:13:27

Spyder
SQLTeam Author

75 Posts

Posted - 2002-02-22 : 02:43:30
Hey, thanks for posting that; looks like that will come in handy!

Go to Top of Page

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2002-02-22 : 08:49:56
Ya ... had to add a reference to a table ... needed a way to find all it's references in the procedures ... made it VERY easy to find them all ... :-) I bet this could be changed to find references of VIEWS, FUNCTIONS, and PROCEDURES within other functions/procedures ...

- Onamuji
Go to Top of Page
   

- Advertisement -