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
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Finding table name if used by any procedure

Author  Topic 

sanjnep
Posting Yak Master

191 Posts

Posted - 2007-11-13 : 10:10:20
I want to find the table name within a database which is being used by any store procedure within this database. Is there any script to do this?
Thanks
Sanjeev

sshelper
Posting Yak Master

216 Posts

Posted - 2007-11-13 : 10:25:37
You can try the sp_depends system stored procedure. Just pass the name of the table as a parameter and it will show you the objects referencing this table:

EXECUTE [dbo].[sp_depends] 'YourTable'

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

sanjnep
Posting Yak Master

191 Posts

Posted - 2007-11-13 : 10:33:59
Thanks a LOT
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-11-13 : 10:50:03
Be aware that will not locate tables referenced in dynamic SQL statements.
The foolproof method is simply to script out all your code and do a text search for the table name.

e4 d5 xd5 Nf6
Go to Top of Page

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2007-11-15 : 10:06:59
Check this out: http://www.sqlservercentral.com/Forums/Topic333827-5-1.aspx
Go to Top of Page

craig79
Starting Member

33 Posts

Posted - 2007-11-23 : 11:55:44
Try this..

select * from dbo.syscomments
where text like '%%' -- put table name within the single quotes..
Go to Top of Page

evilDBA
Posting Yak Master

155 Posts

Posted - 2007-11-23 : 12:32:20
select * from dbo.syscomments
where text like '%%' -- put table name within the single quotes..

This statement works in 99.9% of cases.
Syscomments are stored in chunks, so if table name crosses the boundary this query will not find it.
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-11-24 : 10:15:12
Right. It won't find all the references in a very large stored procedure.

e4 d5 xd5 Nf6
Go to Top of Page
   

- Advertisement -