sqlserver 跨服务器查询

  有两种方法,先记下第一种

sqlserver manager里的新查询中启用

Ad Hoc Distributed Queries:

exec sp_configure 'show advanced options',1 reconfigure 
exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure

---用openDATASOURCE执行

 

select * from OPENDATASOURCE(
'SQLOLEDB',
'Data Source=[IP];User ID=sa;Password=[PW]'
).[库].[用户].[表]
[where ...] 

  

使用完成后,关闭 Ad Hoc Distributed Queries 

 

exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure 

exec sp_configure 'show advanced options',0 reconfigure

posted @ 2016-03-23 13:23  lichjx  阅读(259)  评论(0编辑  收藏  举报