| |

VerySource

 Forgot password?
 Register
Search
View: 637|Reply: 4

How to insert data across databases ???????

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-18 04:20:01
| Show all posts |Read mode
I want to copy the data from another database table
Because the table in the other database is the same as my current table, I want to copy it over
Don't know how to get it
How to batch insert across databases ??????????
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-23 14:18:01
| Show all posts
This can be done with SQL Server's import and export tools.
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-23 14:36:02
| Show all posts
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
Reply

Use magic Report

0

Threads

93

Posts

46.00

Credits

Newbie

Rank: 1

Credits
46.00

 China

Post time: 2020-1-23 23:09:01
| Show all posts
If two databases are on the same machine,
insert B library.dbo.table A
select * from A library.dbo.table A
Reply

Use magic Report

0

Threads

66

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-24 00:09:01
| Show all posts
The stars upstairs are all right
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list