Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old July 28th, 2005, 03:04 PM
pacton pacton is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 1 pacton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 51 m 54 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old July 28th, 2005, 04:33 PM
kcconnor's Avatar
kcconnor kcconnor is offline
Evil Republican...
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2005
Location: Probably running over your cat right now...
Posts: 250 kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level)kcconnor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 21 h 35 m 23 sec
Reputation Power: 37
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.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Script to transfer data between databases


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT