SQL Server的sys.dm_sql_referencing_entities是否需要将对象括起来?

时间:2017-02-16 20:32:57

标签: sql-server

我试图运行SQL Server的sys.dm_sql_referencing_entities存储过程来查看表和sprocs的依赖关系。我为特定的表sys.dm_sql_referencing_entities运行了myTable1,我知道该表在特定的存储过程mySproc2中具有依赖关系。但是,sys.dm_sql_referencing_entities没有返回任何内容。

我注意到在应该使用sys.dm_sql_referencing_entities返回的存储过程中,它没有括号中的myTable。基本上,它是一个简单的查询,看起来像SELECT * FROM myTable1而不是SELECT * FROM [myTable1]

这是否会导致sys.dm_sql_referencing_entities无法返回mySproc2

1 个答案:

答案 0 :(得分:0)

您在SP中引用表格的方式无关紧要。

但是,您应该将表名称作为两部分名称传递给dm_sql_referencing_entities,包括架构。例如:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    ifstream infile("test.txt");
    string line;
    if(infile.is_open())
    {
      cout << infile.rdbuf();
    }
    else
    {
      cout << "error" << endl;
    }
    infile.close();
    return 0;
}

您还应该知道,如果引用来自同一实例上的不同数据库(例如SELECT * FROM sys.dm_sql_referencing_entities ('dbo.Products', 'OBJECT') ,您将不会在结果集中看到该条目。

希望它有所帮助。

相关问题