sql server 跨服务器查询的小例子

发布时间:2020-09-20编辑:脚本学堂
本文介绍一个sql server跨服务器查询的小例子,一段跨库查询的sql语句,有需要的朋友,参考下吧。

服务器查询代码。
 

复制代码 代码示例:

--开始跨库
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

--跨库语句
select * from PJTMA WHERE MA001 not in
(select pjtma006 from OPENROWSET('SQLOLEDB','192.168.1.9';'sa';'SA',
   'SELECT * FROM EF2KWeb.dbo.pjtma') AS a )

--结束跨库后
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure