Home >Database >Mysql Tutorial >How Can I Query Data Across Multiple SQL Servers?
Query data across different SQL Servers
By using linked servers, you can connect to multiple databases on different servers in a single SQL Server query.
Set up linked server
Access the linked server node in Object Explorer at:
<code>服务器对象 --> 链接服务器</code>
Or, execute the sp_addlinkedserver stored procedure.
Query linked table
To reference a table on a linked server in a query, use the following syntax:
<code>SELECT * FROM 本地表, [其他服务器名称].[其他数据库].[dbo].[其他表]</code>
If the schema name is different from the dbo, adjust as needed.
Example
Suppose there are two databases on different servers, containing tables named LocalTable and OtherTable. To perform a cross-server connection, execute the following query:
<code>SELECT * FROM 本地表 INNER JOIN [其他服务器名称].[其他数据库].[dbo].[其他表] ON 本地表.ID = 其他表.ID</code>
The above is the detailed content of How Can I Query Data Across Multiple SQL Servers?. For more information, please follow other related articles on the PHP Chinese website!