所有存储过程中使用的表列表,带有 SP 的模式名称 [英] List of tables used in all stored procedures with SP's schema name
本文介绍了所有存储过程中使用的表列表,带有 SP 的模式名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们如何使用存储过程的模式名称获取所有存储过程中使用的表列表?我在这里看到了一个答案一>.但它没有列出存储过程的模式名称.有人知道如何检索存储过程的模式名称吗?
How do we get list of tables used in all stored procedures with stored procedure's schema name? I have seen an answer here. But it is not listing the stored procedure’s schema name. Does anybody know how to retrieve the schema name of stored procedure too?
推荐答案
试试这个查询:
SELECT *
FROM INFORMATION_SCHEMA.ROUTINES
这将返回当前数据库中的所有存储过程以及与其关联的架构.
This will return all stored procedure in the current database and also the schema associated with it.
如果您想获取表和相关存储过程,请尝试以下操作:
If you want to get the tables and related stored procedure try something like this:
SELECT t.TABLE_NAME, s.ROUTINE_NAME,s.SPECIFIC_SCHEMA
FROM INFORMATION_SCHEMA.TABLES t
INNER JOIN INFORMATION_SCHEMA.ROUTINES s
ON s.ROUTINE_NAME IN
(
SELECT referencing_entity_name
FROM sys.dm_sql_referencing_entities(TABLE_SCHEMA + '.' + TABLE_NAME, 'OBJECT')
)
AND s.ROUTINE_TYPE = 'PROCEDURE'
WHERE t.TABLE_TYPE = 'BASE TABLE'
远离 sysobject 等视图
Stay away from the sysobject etc views
这篇关于所有存储过程中使用的表列表,带有 SP 的模式名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文