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
 New to SQL Server Programming
 Check if table is used/call

Author  Topic 

ryanlcs
Yak Posting Veteran

62 Posts

Posted - 2009-10-27 : 06:04:53
Hi

Is there a way to check if a table is used or call within a stored proc?

Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-10-27 : 07:32:35
duplicate of http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=134971

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

saralstalin
Starting Member

11 Posts

Posted - 2009-10-27 : 07:38:05
1. Run sp_helptext and check the text of the SP. You may also need to check the texts of functions and sproc called within the SP
2. Check the execution plan of the SP.

Rather than manually reading through text you can also run the below query.

SELECT OB.Name, CO.text
FROM sysobjects OB
JOIN syscomments CO ON OB.id=CO.id
WHERE OB.Name = '<SPName>'
AND CO.text like '%<Table Name>%'




Saral S Stalin
Go to Top of Page

saralstalin
Starting Member

11 Posts

Posted - 2009-10-27 : 08:12:10
You can also run

SP_DEPENDS '<storedprocedurename>' to get all dependencies and table calls

Saral S Stalin
Go to Top of Page
   

- Advertisement -