Reputation: 38499
Is there a way of easily retrieving a list of tables underlying a view. For example, in the following view:
CREATE VIEW ExampleView AS
SELECT p.personId, p.surname, p.forename, p.countryCode, c.countryName
FROM persons AS p
INNER JOIN countries AS c ON p.countryCode = c.countryCode
The tables referenced are persons and countries
Is there a way of querying a system table, giving the view name, to get back the tables referenced?
I'm using SQL Server 2008
Upvotes: 0
Views: 138
Reputation: 280252
SELECT * FROM sys.dm_sql_referenced_entities(N'dbo.ExampleView', N'OBJECT');
Upvotes: 1