Home >Database >Mysql Tutorial >How Can I Query Data from Multiple SQL Server Instances in a Single Query?
Query data from multiple servers in SQL Server
When working with data stored on multiple servers, it is often necessary to extract information from different databases and combine it into a single query. In SQL Server, this is achieved through the concept of linked servers.
Use a linked server
To establish a connection between two SQL Server instances, you need to create a linked server. This can be done through SQL Server Management Studio (SSMS) by navigating to:
<code>服务器对象 --> 链接服务器</code>
Alternatively, you can create the link programmatically using the sp_addlinkedserver stored procedure.
Query the data in the linked table
After establishing a linked server, you can access tables on other servers in queries. This is done by specifying the linked server name, followed by the database and table names. For example:
<code>SELECT * FROM 本地表, [其他服务器名称].[其他数据库].[dbo].[其他表]</code>
Note that the table owner (e.g., dbo) may vary, so adjust your query accordingly. This query will extract data from local tables on the current server and other tables on the linked server.
The above is the detailed content of How Can I Query Data from Multiple SQL Server Instances in a Single Query?. For more information, please follow other related articles on the PHP Chinese website!