在SQLServer中是否有DMV来获取对象的依赖关系?

发布于 2024-07-12 21:52:01 字数 62 浏览 5 评论 0原文

我正在寻找一些可以让我获得与选择“查看依赖项”+“[some_table] 依赖的对象”时显示的信息相同的信息

I'm looking for something that would get me the same information that is displayed when I select "View Dependencies" + "Objects on which [some_table] depends"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深缘浅 2024-07-19 21:52:02

如果您使用的是 SQL Server 2008,则以下 SQL 片段将向您显示依赖于 DBO 架构中的 FUND 表的所有对象。

SELECT QUOTENAME(S2.name) + N'.' + QUOTENAME(O2.name) AS ReferencingObject,

 QUOTENAME(S.name) + N'.' + QUOTENAME(O.name) AS ReferencedObject, 

SED.referenced_server_name, SED.referenced_database_name, 

SED.referenced_schema_name, SED.referenced_entity_name

FROM sys.objects AS O

INNER JOIN sys.schemas AS S ON S.schema_id=O.schema_id

INNER JOIN sys.sql_expression_dependencies SED ON SED.referenced_id=O.object_id

INNER JOIN sys.objects O2 ON O2.object_id=SED.referencing_id

INNER JOIN sys.schemas S2 ON S2.schema_id=O2.schema_id

WHERE O.name='FUND' AND S.name='DBO'

请注意,从此 DMV 返回的信息不应不过,可以认为 100% 准确 - 如果您确实需要获得准确的信息,那么 Red-Gate 的 SQL Dependency Tracker 或 ApexSQL 的 Doc 产品都相当不错。

If you are using SQL Server 2008 then the following piece of SQL will show you all of the objects that depend upon the FUND table in the DBO schema.

SELECT QUOTENAME(S2.name) + N'.' + QUOTENAME(O2.name) AS ReferencingObject,

 QUOTENAME(S.name) + N'.' + QUOTENAME(O.name) AS ReferencedObject, 

SED.referenced_server_name, SED.referenced_database_name, 

SED.referenced_schema_name, SED.referenced_entity_name

FROM sys.objects AS O

INNER JOIN sys.schemas AS S ON S.schema_id=O.schema_id

INNER JOIN sys.sql_expression_dependencies SED ON SED.referenced_id=O.object_id

INNER JOIN sys.objects O2 ON O2.object_id=SED.referencing_id

INNER JOIN sys.schemas S2 ON S2.schema_id=O2.schema_id

WHERE O.name='FUND' AND S.name='DBO'

Note that the information coming back from this DMV should not be taken as being 100% accurate though - if you really need to get accurate information then either Red-Gate's SQL Dependency Tracker or ApexSQL's Doc product are fairly good.

别把无礼当个性 2024-07-19 21:52:01

不不准确,看一下 你依赖 sp_depends (没有双关语) 这是我不久前写的

No not accurately, take a look at Do you depend on sp_depends (no pun intended) which I wrote a while back

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文