Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 - Find Which Stored Procs Run To A Particular Table

  • Is there a quick way that I can find which stored procedures run to a particular table in my database?
  • The database is very large with lots of tables and SPROCS....
like image 478
Goober Avatar asked Feb 26 '23 14:02

Goober


2 Answers

If you want to restrict the search to stored procedures then you can do this:

SELECT name
FROM sys.objects
WHERE type = 'P'
    AND OBJECT_DEFINITION(object_id) LIKE '%name_of_your_table%'
ORDER BY name

If you wanted to include other SQL modules -- for examples, functions, triggers, views etc -- then you could alter the query to do WHERE type IN ('P', 'FN', 'IF', 'TF', 'V') etc, or use the alternative given in Martin's answer.

like image 72
LukeH Avatar answered Mar 03 '23 00:03

LukeH


A Combination of looking at dependencies and looking at the text of your objects should do it.

select * from sys.sql_modules
where 
definition like '%tableName%'
/*AND objectproperty(object_id,'isprocedure')=1 to just look at procedures*/

exec sp_depends 'tableName'
like image 40
Martin Smith Avatar answered Mar 03 '23 00:03

Martin Smith