惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

M
MIT News - Artificial intelligence
有赞技术团队
有赞技术团队
S
Schneier on Security
aimingoo的专栏
aimingoo的专栏
T
Troy Hunt's Blog
U
Unit 42
Hacker News - Newest:
Hacker News - Newest: "LLM"
V2EX - 技术
V2EX - 技术
T
The Blog of Author Tim Ferriss
V
Visual Studio Blog
H
Heimdal Security Blog
H
Hacker News: Front Page
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Cloudbric
Cloudbric
Google DeepMind News
Google DeepMind News
C
Cisco Blogs
The Cloudflare Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
MyScale Blog
MyScale Blog
F
Fortinet All Blogs
N
News | PayPal Newsroom
Attack and Defense Labs
Attack and Defense Labs
D
DataBreaches.Net
N
News and Events Feed by Topic
Security Archives - TechRepublic
Security Archives - TechRepublic
Forbes - Security
Forbes - Security
Simon Willison's Weblog
Simon Willison's Weblog
F
Full Disclosure
The Register - Security
The Register - Security
L
LINUX DO - 热门话题
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
AI
AI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
S
Security Affairs
阮一峰的网络日志
阮一峰的网络日志
K
Kaspersky official blog
云风的 BLOG
云风的 BLOG
博客园 - 叶小钗
T
Threatpost
Spread Privacy
Spread Privacy
小众软件
小众软件
AWS News Blog
AWS News Blog
S
Secure Thoughts
S
Security @ Cisco Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
J
Java Code Geeks

博客园 - 涂文瀚

常用的前端调试工具 用户中心 - 博客园 SQL中动态进行行转列 SQL SERVER 表分区实施步奏 PHP常见面试问题 在WIN下搭建PHP的测试、开发环境 [转]三款免费的PHP加速器:APC eAccelerator XCache比较 Xdebug如何选择PHP版本 PHP Cookbook读书笔记 – 第01章字符串 PHP Cookbook读书笔记 – 第03章日期和时间 PHP Cookbook读书笔记 – 第02章数字 PHP Cookbook读书笔记 – 第04章数组 PHP Cookbook读书笔记 – 第06章函数 PHP Cookbook读书笔记 – 第07章类和对象 PHP Cookbook读书笔记 – 第08章web基础 设计模式之观察者模式 PHP Cookbook读书笔记 – 第09章表单 PHP Cookbook读书笔记 – 第11章Session和持久化 PHP Cookbook读书笔记 – 第12章XML
[记录]SQL SERVER 跨库操作小记
涂文瀚 · 2012-03-03 · via 博客园 - 涂文瀚

当2个库在同一台服务器的情况

1 --同一服务器
2
3 insertinto dbo.TESTA select*from dbo.TESTB

当2个库在不同的服务器的情况

 1 /*不同服务器数据库之间的数据操作*/
2
3 --创建链接服务器
4 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 '
5 exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, '用户名 ', '密码 '
6
7 --查询示例
8 select * from ITSV.数据库名.dbo.表名
9
10 --导入示例
11 select * intofrom ITSV.数据库名.dbo.表名
12
13 --以后不再使用时删除链接服务器
14 exec sp_dropserver 'ITSV ', 'droplogins '
15
16 --连接远程/局域网数据(openrowset/openquery/opendatasource)
17 --1、openrowset
18
19 --查询示例
20 select * from openrowset( 'SQLOLEDB ', 'sql服务器名 '; '用户名 '; '密码 ',数据库名.dbo.表名)
21
22 --生成本地表
23 select * intofrom openrowset( 'SQLOLEDB ', 'sql服务器名 '; '用户名 '; '密码 ',数据库名.dbo.表名)
24
25 --把本地表导入远程表
26 insert openrowset( 'SQLOLEDB ', 'sql服务器名 '; '用户名 '; '密码 ',数据库名.dbo.表名)
27 select *from 本地表
28
29 --更新本地表
30 update b
31 set b.列A=a.列A
32 from openrowset( 'SQLOLEDB ', 'sql服务器名 '; '用户名 '; '密码 ',数据库名.dbo.表名)as a inner join 本地表 b
33 on a.column1=b.column1
34
35 --openquery用法需要创建一个连接
36
37 --首先创建一个连接创建链接服务器
38 exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '远程服务器名或ip地址 '
39 --查询
40 select *
41 FROM openquery(ITSV, 'SELECT * FROM 数据库.dbo.表名 ')
42 --把本地表导入远程表
43 insert openquery(ITSV, 'SELECT * FROM 数据库.dbo.表名 ')
44 select * from 本地表
45 --更新本地表
46 update b
47 set b.列B=a.列B
48 FROM openquery(ITSV, 'SELECT * FROM 数据库.dbo.表名 ') as a
49 inner join 本地表 b on a.列A=b.列A
50
51 --3、opendatasource/openrowset
52 SELECT *
53 FROM opendatasource( 'SQLOLEDB ', 'Data Source=ip/ServerName;User ID=登陆名;Password=密码 ' ).test.dbo.roy_ta
54 --把本地表导入远程表


内容来源于csdn,原讨论贴地址:

http://topic.csdn.net/u/20110331/10/c2efd600-d94b-45d4-b4cc-3fc2901426a9.html