--启用Ad Hoc Distributed Queries:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
--查询示例(使用openrowset或opendatasource函数)
select * from openrowset('SQLOLEDB' , 'sql服务器名' ; '用户名' ; '密码' , 数据库名.dbo.表名)
select * from openrowset('SQLOLEDB' , '6f1ce7ba506f49b' ; 'sa' ; '168' , cw202.dbo.bmzl)
select a.* from opendatasource('sqloledb','server=服务器名或实例名;uid=sa;pwd=;database=库名').库名.dbo.table1 a
select a.* from opendatasource('sqloledb','server=6f1ce7ba506f49b;uid=sa;pwd=168;database=cw202').cw202.dbo.bmzl a
--使用完成后,关闭Ad Hoc Distributed Queries:
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure