SQL跨服查询
今日产品部要导批数据,但是需要连接查询查询的几个表不在同一服务器上。所以我开始是这么干的:
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.查询
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
相关文档:
测试机test安装的是windows server2008+sql server 2008,数据库安装成功。可以连接局域网内其他机器的数据库(其他机器的数据库为SQL 2005)。但是网内其他机器访问test时,无法连接,报错。信息为:在建立与服务器的连接时出错。在连接到SQL SERVER 2005时,在默认的设置下SQL SERVER 不允许进行远程连接可能会导致次失败 ......
一、问题
select UserID,LastName,FirstName,UserName from SYSUser
UserID LastName FirstName UserName
------------------------------------------------------
1 A B C
2 &nb ......
The following tables describe certain SQL
limits. Adhering to the most restrictive case can help the programmer
design application programs that are easily portable.
Table 7. Identifier Length Limits
Description
Limit in Bytes
Longest authorization
name (can only be single-byte characters) ......
create table tabReProc
(
name varchar(30),
age integer,
primary key(name,age)
)
insert into tabReProc values('x7700',20)
insert into tabR ......
我理解的SQL Server 2005镜像配置实际上就是由三个服务器(也可以是同一服务器的三个 SQL 实例)组成的一个保证数据的环境,分别是:主服务器、从服务器、见证服务器。
主服务器:数据存放的地方
从服务器:数据备份的地方(即:主服务器的镜像)
见证服务器:动态调配主/从服务器的第三方服务器
环境介绍
首先介 ......