Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find which views are using a certain table in SQL Server (2008)?

I have to add a few columns to a table and I also need to add these columns to all the views that use this table.

Is it possible to get a list of all the views in a database that use a certain table?

like image 794
Peter Avatar asked Mar 08 '12 13:03

Peter


People also ask

How do you find which views are using a certain table in SQL?

If you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).

How do you check if a table is used in any view in SQL Server?

To find all of the SQL Server database views where a table is used, just apply a filter criteria on table_name column of the information schema view INFORMATION_SCHEMA. VIEW_TABLE_USAGE as seen below.


1 Answers

This should do it:

SELECT *  FROM   INFORMATION_SCHEMA.VIEWS  WHERE  VIEW_DEFINITION like '%YourTableName%' 
like image 59
James Hill Avatar answered Oct 09 '22 06:10

James Hill