我有三个存储过程让我们说A,B和C. SP将数据插入到X表中,其中B将数据插入到Y表中。现在,我需要一个查询来动态列出SP及其目标表。表和SP之间没有引用/依赖。
答案 0 :(得分:0)
这是您要求的查询。您可以使用where Clause
在此查询中按过程名称和表名称使用过滤器。
WITH ABC AS (
SELECT
So.name AS ProcedureName, SOO.Name AS TableName,
ROW_NUMBER() OVER(partition by SO.Name,SOO.Name ORDER BY SO.Name,SOO.Name) AS R
FROM sysdepends SD
INNER JOIN sysobjects SO ON SO.id=Sd.id
INNER JOIN sysobjects SOO ON Soo.id=Sd.depid
WHERE So.Xtype = 'P')
SELECT ProcedureName, TableName FROM ABC
WHERE R = 1
ORDER BY ProcedureName,TableName