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 2008 Forums
 Transact-SQL (2008)
 Finding table occurence in Stored proc

Author  Topic 

Sql_forum
Yak Posting Veteran

50 Posts

Posted - 2012-04-10 : 07:29:12
Hi i have a table with name some 'XYZ'

and it is used in many stored procs.

Now pls tell me how to findout in which all procedured table 'XYZ' is used???

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-10 : 07:31:24
[code]SELECT
[name]
FROM
sys.objects
WHERE
OBJECT_DEFINITION(OBJECT_ID) LIKE '%XYZ%'
AND [type] = 'P'[/code]
Go to Top of Page

Sql_forum
Yak Posting Veteran

50 Posts

Posted - 2012-04-10 : 07:44:04
Thanks Sunita :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-10 : 15:57:02
please keep in mind that this wont return the stored procedures where table is used inside a dynamic sql string. for finding them you might need to use sys.sql_modules

http://visakhm.blogspot.com/2012/03/advantages-of-using-syssqlmodules-view.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-10 : 17:24:06
quote:
Originally posted by visakh16

please keep in mind that this wont return the stored procedures where table is used inside a dynamic sql string. for finding them you might need to use sys.sql_modules

http://visakhm.blogspot.com/2012/03/advantages-of-using-syssqlmodules-view.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



I am not able to see why this would be so, given that both the query I posted and sys.sql_modules use object_definition(object_id) to retrieve the stored procedure definition.
Go to Top of Page
   

- Advertisement -