2017-10-19 69 views
1

是否有查询来获取我的表所依赖的表的列表?我已经试过sys.sql_expression_dependencies,sys.dm_sql_referencing_entities,sp_depends, information_schema.routines我的表依赖于sql服务器的对象

这给依赖于我的表的对象。这是我曾尝试查询:

sp_depends 'dbo.buyer' 

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

SELECT OBJECT_NAME(referencing_id),* FROM sys.sql_expression_dependencies 
WHERE referencing_id = OBJECT_ID('dbo.buyer') 

SELECT OBJECT_NAME(referencing_id),* FROM 
ims.sys.sql_expression_dependencies 
WHERE referenced_id = OBJECT_ID('ims.dbo.buyer'); 

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

回答

0

试试这个

SELECT DISTINCT t.name 
FROM sys.foreign_key_columns as fk 
INNER JOIN sys.tables as t 
ON fk.referenced_object_id = t.object_id 
INNER JOIN sys.tables as t2 
ON fk.parent_object_id = t2.object_id 
WHERE t2.name = 'yourTableName'