What database/procedure is using a linked server?

 /* How can I tell what database/procedure is using a linked server? */

/* How to check if MS SQL Server, Linked Server object is in use */


/************** Example 1  *********************/

SELECT 

    Distinct 

    referenced_Server_name As LinkedServerName,

    referenced_schema_name AS LinkedServerSchema,

    referenced_database_name AS LinkedServerDB,

    referenced_entity_name As LinkedServerTable,

    OBJECT_NAME (referencing_id) AS ObjectUsingLinkedServer

FROM sys.sql_expression_dependencies

WHERE referenced_database_name IS NOT NULL

And referenced_Server_name = 'Linked Server Name'


/************** Example 2  *********************/

SELECT DISTINCT 

    referenced_Server_name AS LinkedServerName,

    referenced_schema_name AS LinkedServerSchema,

    referenced_database_name AS LinkedServerDB,

    referenced_entity_name AS LinkedServerTable,

    OBJECT_NAME (referencing_id) AS ObjectUsingLinkedServer

FROM sys.sql_expression_dependencies

WHERE referenced_database_name IS NOT NULL

AND referenced_database_name='database name'

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^