inserting data from one database on one server to another database on other server
Is it 开发者_C百科possible using management studio make such a query ? I just want to copy data from one table to another but these are on other servers.
Select * From ServerName1.DbName1.SchemaName1.TableName1
from the other server should get the data for you.
All you need to do is use full sql object naming conventions.
which is
[ServerName].[DbName].[SchemaName].[TableName]
If the servers aren't linked, you might want to look at the "SQL Server Import and Export Wizard", found via Right-clicking a database, and choosing Tasks->Export Data.
This works by building an SSIS package, which (if you're doing this task regularly) you might wish to save
you have to create a linked server first.
for SQL Server 2012 it would be :-
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver @server = N'<SERVERNAME>', @srvproduct=N'SQL Server'
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'<SERVERNAME>',@useself=N'False',@locallogin=NULL,@rmtuser=NULL,@rmtpassword=NULL
EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'<SERVERNAME>',@useself=N'False',@locallogin=N'sa',@rmtuser=N'sa',@rmtpassword='########'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'collation compatible', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'data access', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'dist', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'pub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'rpc', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'rpc out', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'sub', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'connect timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'collation name', @optvalue=null
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'lazy schema validation', @optvalue=N'false'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'query timeout', @optvalue=N'0'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'use remote collation', @optvalue=N'true'
GO
EXEC master.dbo.sp_serveroption @server=N'<SERVERNAME>', @optname=N'remote proc transaction promotion', @optvalue=N'true'
GO
then you can use every table from linked server mentioning the server name using full sql object naming conventions like :-
select *
from [server1].[database].[schema].[table] as t1
inner join [server2].[database].[schema].[table] as t2
on t1.columnname = t2.columnname
精彩评论