Home > Database > Mysql Tutorial > body text

实战操作SQL Server连接查询不同服务器表数据

WBOY
Release: 2016-06-07 17:54:14
Original
1042 people have browsed it

今日产品部要导批数据,但是需要连接查询查询的几个表不在同一服务器上。所以我开始是这么干的: 1.查询一台服务器的数据,并导入本地Excel 2.查询另一台服务器的数据,并导入本地Excel 3.Excle导入数据库,数据库自带了Excel导入数据库的功能 4.连接查询,O

    今日产品部要导批数据,但是需要连接查询查询的几个表不在同一上。所以我开始是这么干的:

  1.查询一台服务器的数据,并导入本地Excel

  2.查询另一台服务器的数据,并导入本地Excel

  3.Excle导入,自带了Excel导入数据库的功能

导入数据库

  4.连接查询,OVER!

  后来才知道产品部要全国50多个城市的数据,所以每个城市的我都要重复这样干一遍。

  这时才想起跨库查询了。

  1.开通分布式查询权限

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

   2.查询

select a.ProjCode as '楼盘编号',b.projname as '楼盘名称',count(1) as '房源量' from    openrowset( 'SQLOLEDB ', 'IP地址(服务器名)'; '用户名'; '密码',[数据库名].[dbo].[表名]) a   , openrowset( 'SQLOLEDB ', 'IP地址(服务器名)'; '用户名'; '密码',[数据库名].[dbo].[表名]) b   where a.ProjCode=b.newcode GROUP by   a.ProjCode ,b.projname order by  count(1) desc

          3.然后换城市,只需要改IP、 库名和表名了。

          4.关闭

exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!