How to check if database exist on Remote Server through SQL query

前端 未结 2 1245
野的像风
野的像风 2021-01-16 16:47

I have a table as following in SQL Server 2012.

|---------------------|------------------|------------------|
|      ClientName     |     servername   |Datab         


        
2条回答
  •  不要未来只要你来
    2021-01-16 17:42

    Is there a way to return only rows for which database exists on the server names mentioned in the table?

    I want it to be part of where clause.

    If I understand your question correctly, you can use where exists

    e.g. (you need to have server1 as linked server from the server that you are running the query from)

    select * from 
    schema.yourTable
    where exists (select 1 from Server1.dbname.schemaName.yourServerList
                     where DatabaseName = 'b1')
    

提交回复
热议问题