这篇文章主要为大家详细介绍了SQL Server 多表查询不同数据库服务器上的表,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
第一种方法:代码如下:
/* 创建链接服务器 */
exec sp_addlinkedserver 'srv_lnk','','sqloledb','条码数据库IP地址'
exec sp_addlinkedsrvlogin 'srv_lnk','false',null,'用户名','密码'
go
/* 查询示例 */
SELECT A.ListCode
FROM srv_lnk.条码数据库名.dbo.ME_ListCode A, IM_BarLend B
WHERE A.ListCode=B.ListCode
go
/* 删除链接服务器 */
exec sp_dropserver 'srv_lnk','droplogins'
代码如下:
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
go
select * from Product p inner join
opendatasource('SQLOLEDB','Data Source=Macaco-Online;user ID=sa;password=sa密码;').Company.dbo.Product p2
on P.PID=p2.PID
go
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
go
本文来自:http://www.q1010.com/179/7903-0.html
注:关于SQL Server 多表查询不同数据库服务器上的表的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:SQL SERVER
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。