Selecting data from two different servers in SQL Server

后端 未结 15 1950

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

15条回答
  •  清歌不尽
    2020-11-22 08:04

    What you are looking for are Linked Servers. You can get to them in SSMS from the following location in the tree of the Object Explorer:

    Server Objects-->Linked Servers

    or you can use sp_addlinkedserver.

    You only have to set up one. Once you have that, you can call a table on the other server like so:

    select
        *
    from
        LocalTable,
        [OtherServerName].[OtherDB].[dbo].[OtherTable]
    

    Note that the owner isn't always dbo, so make sure to replace it with whatever schema you use.

提交回复
热议问题