Find all views containing specific table names

时间:2018-06-04 16:40:37

标签: sql sql-server

I have several views in my database that are built on tables.

Is it possible to query for view names which contain specific tables in it?

For example by using:

Where tablename like '%TableA%' 

I tried

SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME LIKE '%TableA%'

But this gives list of tables created using this table.

1 个答案:

答案 0 :(得分:0)

Use the following query to search views for a table:

SELECT Objects.name, Modules.definition
FROM sys.sql_modules AS Modules INNER JOIN sys.objects AS Objects ON         
Modules.object_id = Objects.object_id
WHERE definition like '%TableA%'