您现在的位置是:网站首页> 编程资料编程资料
sqlserver 多表查询不同数据库服务器上的表_MsSql_
2023-05-26
720人已围观
简介 sqlserver 多表查询不同数据库服务器上的表_MsSql_
第一种方法:
/* 创建链接服务器 */
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
复制代码 代码如下:
/* 创建链接服务器 */
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
您可能感兴趣的文章:
上一篇:存储过程优缺点分析_MsSql_
相关内容
- 存储过程优缺点分析_MsSql_
- SQLSERVER 创建索引实现代码_MsSql_
- 优化SQL Server的内存占用之执行缓存_MsSql_
- SQLServer 跨库查询实现方法_MsSql_
- sqlserver 2000中创建用户的图文方法_MsSql_
- SQL SERVER 与ACCESS、EXCEL的数据转换方法分享_MsSql_
- 数据库中聚簇索引与非聚簇索引的区别[图文]_MsSql_
- SQLServer 2000 升级到 SQLServer 2008 性能之需要注意的地方之一_MsSql_
- 只有mdf文件的数据库附加失败的修复方法分享(置疑、只读)_MsSql_
- sqlserver 锁表语句分享_MsSql_
