Selecting data from two different servers in SQL Server

后端 未结 15 1724

How can I select data in the same query from two different databases that are on two different servers in SQL Server?

15条回答
  •  旧时难觅i
    2020-11-22 08:17

    As @Super9 told about OPENDATASOURCE using SQL Server Authentication with data provider SQLOLEDB . I am just posting here a code snippet for one table is in the current sever database where the code is running and another in other server '192.166.41.123'

    SELECT top 2 * from dbo.tblHamdoonSoft  tbl1 inner JOIN  
    OpenDataSource('SQLOLEDB','Data Source=192.166.41.123;User ID=sa;Password=hamdoonsoft')
    .[TestDatabase].[dbo].[tblHamdoonSoft1] tbl2 on tbl1.id = tbl2.id
    

提交回复
热议问题