Get All Tables Referenced by at Least One View

Get All Tables Referenced by at Least One View

The following query will produce a list of tables that are referenced by one or more Views:

SELECT [table] = + N'.' +  FROM sys.tables AS t  INNER JOIN sys.schemas AS s  ON t.[schema_id] = s.[schema_id]  WHERE EXISTS  (    SELECT 1 FROM sys.tables AS st      INNER JOIN sys.schemas AS ss      ON st.[schema_id] = ss.[schema_id]      CROSS APPLY sys.dm_sql_referencing_entities        (QUOTENAME( + N'.' + QUOTENAME(,          N'OBJECT') AS r      INNER JOIN sys.views AS v      ON v.[object_id] = r.referencing_id      INNER JOIN sys.schemas AS vs      ON v.[schema_id] = vs.[schema_id]      WHERE st.[object_id] = t.[object_id]  )

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist