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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 涂文瀚

常用的前端调试工具 如何在IIS7(WIN2008)中部署你的MVC网站 - 涂文瀚 SQL中动态进行行转列 SQL SERVER 表分区实施步奏 PHP常见面试问题 在WIN下搭建PHP的测试、开发环境 [转]三款免费的PHP加速器:APC eAccelerator XCache比较 Xdebug如何选择PHP版本 PHP Cookbook读书笔记 – 第01章字符串 PHP Cookbook读书笔记 – 第02章数字 PHP Cookbook读书笔记 – 第03章日期和时间 - 涂文瀚 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