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

泄露秘密 提交于 2019-12-30 10:30:58

问题


  • 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....

回答1:


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.




回答2:


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'


来源:https://stackoverflow.com/questions/3361141/sql-server-2005-find-which-stored-procs-run-to-a-particular-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!