Home > Mobile >  Querying dependencies: Objects on which a view depends
Querying dependencies: Objects on which a view depends

Time:05-27

I'm trying to find out how to script referencing entities for a view.

To find objects that depend on I'm using the following script:

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

However, what I'm trying to find out is: objects on which my view depends.

Through SQL Management Studio I can find them in the UI with the option on the picture below.

enter image description here

Is it possible to get to this data through a script?

CodePudding user response:

The opposite to sys.dm_sql_referencing_entities is sys.dm_sql_referenced_entities, which works identically to the former function, just the other way round; it gives objects that object depends on, not objects that depend on it. So you would literally just replace the function name:

SELECT referencing_schema_name,
       referencing_entity_name,
       referencing_id,
       referencing_class_desc,
       is_caller_dependent
 FROM sys.dm_sql_referenced_entities ('dbo.my_view', 'OBJECT');

CodePudding user response:

Use sys.dm_sql_referenced_entities

  • Related