Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding all views that are using linked server

I am updating url for linked servers. Before make the changes, I would like to know all views that have reference to this linked servers. Is there any programmatic way (TSQL) to perform this task?

Thanks for your help.

I am using SQL Server 2005, 2008 and 2012. The database servers that referencing linked servers are mostly SQL Server 2005

like image 337
Wei Ma Avatar asked Feb 26 '26 12:02

Wei Ma


1 Answers

While it may return false positives, and won't capture any cases where a four-part name is constructed using dynamic SQL, this is probably the simplest approach:

SELECT name FROM sys.views
WHERE LOWER(OBJECT_DEFINITION([object_id])) LIKE LOWER('%LinkedServerName%');
like image 144
Aaron Bertrand Avatar answered Mar 01 '26 10:03

Aaron Bertrand



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!