|
If two databases are on the same server, you can directly
insert into tablename (column name 1, column name 2 ...)
select (corresponding to column name 1, corresponding to column name 2 ...) from [DataBaseName] .dbo.tablename
If there are two databases on two servers, you need to establish a connection server.
--Create a linked server
exec sp_addlinkedserver 'srv_lnk', '', 'SQLOLEDB', 'Remote server name or IP address'
exec sp_addlinkedsrvlogin 'srv_lnk', 'false', null, 'user name', 'password'
go
-
insert into tablename (column name 1, column name 2 ...)
select (corresponding to column name 1, corresponding to column name 2 ...) from srv_lnk. [DataBaseName] .dbo.tablename |
|