【sql】跨链接复制表

create database SampleTestingSysDB
go
use SampleTestingSysDB
go

EXEC sp_addlinkedserver
@server='oldDB',--被访问的服务器别名
@srvproduct='',
@provider='SQLOLEDB',
@datasrc='ip,端口' --要访问的服务器
go

EXEC sp_addlinkedsrvlogin
'oldDB', --被访问的服务器别名
'false',
NULL,
'sa', --帐号
'***' --密码
go

select * into [SampleTestingSysDB].dbo.Batch_Nucleic from  [oldDB].[SampleTestingSysDB].dbo.Batch_Nucleic
select * into [SampleTestingSysDB].dbo.Batch_NucleicSampleLog from  [oldDB].[SampleTestingSysDB].dbo.Batch_NucleicSampleLog
select * into [SampleTestingSysDB].dbo.Batch_Test from  [oldDB].[SampleTestingSysDB].dbo.Batch_Test
select * into [SampleTestingSysDB].dbo.Batch_TestSampleLog from  [oldDB].[SampleTestingSysDB].dbo.Batch_TestSampleLog
select * into [SampleTestingSysDB].dbo.Sample_BarCode from  [oldDB].[SampleTestingSysDB].dbo.Sample_BarCode
select * into [SampleTestingSysDB].dbo.Sample_Estimate from  [oldDB].[SampleTestingSysDB].dbo.Sample_Estimate
select * into [SampleTestingSysDB].dbo.Sample_Nucleic from  [oldDB].[SampleTestingSysDB].dbo.Sample_Nucleic
select * into [SampleTestingSysDB].dbo.Sample_ResultLog from  [oldDB].[SampleTestingSysDB].dbo.Sample_ResultLog
select * into [SampleTestingSysDB].dbo.Sample_Service from  [oldDB].[SampleTestingSysDB].dbo.Sample_Service
select * into [SampleTestingSysDB].dbo.Sys_Account from  [oldDB].[SampleTestingSysDB].dbo.Sys_Account
select * into [SampleTestingSysDB].dbo.Sys_AccountLog from  [oldDB].[SampleTestingSysDB].dbo.Sys_AccountLog
select * into [SampleTestingSysDB].dbo.Sys_AuthJoinAccountJoinPermissions from  [oldDB].[SampleTestingSysDB].dbo.Sys_AuthJoinAccountJoinPermissions
select * into [SampleTestingSysDB].dbo.Sys_AuthJoinResource from  [oldDB].[SampleTestingSysDB].dbo.Sys_AuthJoinResource
select * into [SampleTestingSysDB].dbo.Sys_AuthList from  [oldDB].[SampleTestingSysDB].dbo.Sys_AuthList
select * into [SampleTestingSysDB].dbo.Sys_AuthResource from  [oldDB].[SampleTestingSysDB].dbo.Sys_AuthResource
select * into [SampleTestingSysDB].dbo.Sys_Menus from  [oldDB].[SampleTestingSysDB].dbo.Sys_Menus

declare @id uniqueidentifier
set @id = ''
insert into [oldDB].[PetsMallDB].[dbo].[Member_Pet] select * from  [PetsMallDB].[dbo].Member_Pet where MemberId = @id

-- 删除登录
sp_droplinkedsrvlogin 'oldDB',null
go

--删除数据库连接
exec sp_dropserver 'oldDB'
go

posted @ 2022-07-26 12:21  lanofsky  阅读(43)  评论(0编辑  收藏  举报