|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Script to transfer data between databases
I'm a newbie to SQL Server.
I'm wondering if someone could help me get started with writing a script with the following assumptions 2 databases named db1 and db2, each with a table that are named identical table1. I would like a script that would move any rows that exist in db2.table1 and don't exist in db1.table1 to be moved there. Any rows that do exist in db1 as well as db2 I would like to move the contents of one of the fields from db2.table1 to db1.table1. I hope this makes sense, and thank you very much for any help. Paul |
|
#2
|
||||
|
||||
|
Code:
insert into db1..table1 select * from db2..table1 where primary_key not in (select primary_key from db1..table1) That will insert all rows to db1 that are present in db2 but not currently in db1. I don't think I understand the other half of the problem. |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Script to transfer data between databases |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|