I'm working in Microsoft SQL Server and was asked what tables does a certain view gets its data. I tried using the dependencies tab but all I see is the name of the view. What does this mean? I have verified that it is in fact a view.
I tried using
SELECT definition
FROM sys.sql_modules
WHERE object_id = OBJECT_ID('NameOfView');
I also tried
EXEC sp_helptext 'NameofView';
Lastly,
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.VIEW_COLUMN_USAGE
WHERE VIEW_NAME = 'NameofView';
None of these returned anything.
2条答案
按热度按时间pes8fvy91#
You can use
sys.dm_sql_referenced_entities
9q78igpj2#
You asked:
what tables does a certain view gets its data
The reality is 99% of people script the view in the SSMS Object Explorer and look at the query executed by the view. The query contains the tables used.
Right-click the view in SSMS Object Explorer > Script View As > Create To > New Query Window. The tables used will be displayed in the view script.
I can't think of any good reason to ask this question outside of an interview question to test your knowledge of SSMS or if your co-worker was too lazy to script it out themselves.