我想找到所有正在使用特定表的存储过程。数据库中有很多存储过程,因此检查每个过程是不可行的。
有什么方法可以使用搜索查询,以便我可以找到存储过程?
我已经试过这段代码:
SELECT distinct so.name FROM syscomments sc INNER JOIN sysobjects so ON sc.id=so.id WHERE sc.TEXT LIKE '% RejectionReason %'
RejectionReason我的表名在哪里,但是它显示了所有在哪里RejectionReason用作列名的过程,所以这是行不通的。
RejectionReason
SELECT o.name, o.type_desc, p.name, p.type_desc FROM sys.sql_dependencies d INNER JOIN sys.objects o ON d.object_id = o.object_id INNER JOIN sys.objects p ON d.referenced_major_id = p.object_id AND o.name = ‘RejectionReason’
或者
SELECT o.name, t.TABLE_NAME, c.text FROM syscomments c JOIN sysobjects o ON c.id = o.id JOIN INFORMATION_SCHEMA.Tables t ON c.text LIKE '%RejectionReason%'
EXEC sp_depends @objname = N'RejectionReason';