How do you join tables from two different SQL Server instances in one SQL query [duplicate]

会有一股神秘感。 提交于 2019-12-18 14:23:21

问题


Possible Duplicate:
Selecting data from two different servers in SQL Server

How can I join two tables, which are located two different SQL Server instances, in one query?


回答1:


The best way I can think of to accomplish this is via sp_addlinkedserver. You need to make sure that whatever account you use to add the link (via sp_addlinkedsrvlogin) has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:

SELECT *
FROM server1table
    INNER JOIN server2.database.dbo.server2table ON .....



回答2:


You can create a linked server and reference the table in the other instance using its fully qualified Server.Catalog.Schema.Table name.




回答3:


If you are using SQL Server try Linked Server



来源:https://stackoverflow.com/questions/1423907/how-do-you-join-tables-from-two-different-sql-server-instances-in-one-sql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!