I have a view-A that is comprised of other views (View-B View-C) and I would like to list all the tables that used by View-A (which would include the tables used in View-B and View-C). When I use this code...
-- Get base tables for 'View-A' in Database-A
USE Database-A
GO
SELECT view_name, Table_Name
FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE
WHERE View_Name = 'View-A'
ORDER BY view_name, table_name
GO
...I only get the tables that are immediately used by View-A plus the name of the other views (View-B, View-C). Is there a way to get recursively the names of the tables that are also used by View-B and View-C?
DISTINCT
to the select after the CTE. stackoverflow.com/a/2566927/775200