Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2005 search views for certain database objects

Is there a way in SQL Server to list all the views within a database that join from a particular object?

ie: find all the views that join from the table myTable

like image 879
yogibear Avatar asked Feb 15 '26 13:02

yogibear


1 Answers

You can use sys.sql_dependencies:

select object_name(object_id),* 
from sys.sql_dependencies
where referenced_major_id = object_id('<tablename>');

This will list all objects that depend on your table, you can restrict this to views by joining against sys.views:

select v.* 
from sys.sql_dependencies d
join sys.views v on d.object_id = v.object_id
where referenced_major_id = object_id('<tablename>');
like image 95
Remus Rusanu Avatar answered Feb 17 '26 02:02

Remus Rusanu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!