如何在sql server中查找表的所有依赖项 [英] How to find all the dependencies of a table in sql server

查看:80
本文介绍了如何在sql server中查找表的所有依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库,其中包含表、过程、视图和触发器的列表.但我想要一个查询来获取表的所有依赖项,包括引用父表的子表.

I have a database where i have list of tables,procedures,views and triggers. But i want a query to get all the dependencies of a table including child tables which are referring the parent table.

推荐答案

以下是我们可以用来检查依赖项的方法:

The following are the ways we can use to check the dependencies:

方法一:使用sp_depends

 sp_depends 'dbo.First'
 GO

方法二:使用information_schema.routines

 SELECT *
 FROM information_schema.routines ISR
 WHERE CHARINDEX('dbo.First', ISR.ROUTINE_DEFINITION) > 0
 GO

方法 3:使用 DMV sys.dm_sql_referencing_entities

Method 3: Using DMV sys.dm_sql_referencing_entities

 SELECT referencing_schema_name, referencing_entity_name,
 referencing_id, referencing_class_desc, is_caller_dependent
 FROM sys.dm_sql_referencing_entities ('dbo.First', 'OBJECT');
 GO

这篇关于如何在sql server中查找表的所有依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆