SQLServer将一个表的数据导入到另一个表
B表数据转移到A表
1、假如A表存在
INSERT INTO A(a,b,c) (SELECT a,b,c FROM B)
2、假如A表不存在
SELECT a,b,c INTO A FROM B
3、假如需要跨数据库
INSERT INTO A库.[dbo].A表(a,b,c) (SELECT a,b,c FROM B库.[dbo].B表)
4.跨服务器转移
--开启Ad Hoc Distributed Queries组件
exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
**--创建链接服务器(连接B表服务器)
exec sp_addlinkedserver ''srv_lnk'','''',''SQLOLEDB'',''远程服务器名或ip地址''
exec sp_addlinkedsrvlogin ''srv_lnk'',''false'',null,''用户名'',''密码''
go
--写入数据
select * into A from srv_lnk.数据库名.dbo.B
go
--关闭链接服务器
exec sp_dropserver 'srv_lnk', 'droplogins'
--关闭Ad Hoc Distributed Queries组件(用完以后关)
exec sp_configure 'Ad Hoc Distributed Queries',0
reconfigure
exec sp_configure 'show advanced options',0
reconfigure
更多推荐
SQLServer将一个表的数据导入到另一个表
发布评论