Linking databases from Different servers in a query

  • I have 2 servers 'ServerA' and 'ServerB'

    I have a table 'TableS1'  in 'ServerA' and a table 'TableS2' in 'ServerB'

    I need to link 2 tables TableS1 and TablesS2 in a query.

    Please help.

    Regards,

    Rohini

     

  •  

    You can link servers by adding a linked server....

    For this, you first need to create a linked server which requires sysadmin or setupadmin privileges..

    EXEC sp_addlinkedserver N'YourServerName' , N'SQL Server'

    Then you can use this linked server in your queries..

    SELECT * FROM [YourServerName].[YourDatabase].[Owner].[YourTable]

     

     

     

    --Ramesh


  • I would avoid doing this if you can. Cross server joins are usually VERY slow. It's much better to have both tables you want to join on the same server if you can get away with it. It's fine if they are in different databases, just put them on the same server.

    ---------------------------------------
    elsasoft.org

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply