MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

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 Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old February 16th, 2004, 07:01 AM
wheetomeister wheetomeister is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 3 wheetomeister User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Merge 12 databases

Hello all,

I have a question regarding the merging of data using SQL server. I have 12 separate databases, all with the same referential structure and tables etc. but with different data in them. What I want to do is merge all the data from these 12 into 1 large database, again with the same structure. The tables within these databases comprise foreign keys from ids, and the 12 databases contain some duplicates of these keys, so I will need some method of re-assigning these ids during the merge to avoid conflicts.

So far I have looked at using DTS, and also just using queries but have had only limited success. An ideal outcome would be for me to create some kind of script for doing this as the merge would need to be completed on a regular basis.

Any help would be very much appreciated!!!

Reply With Quote
  #2  
Old March 30th, 2004, 05:14 PM
mateoc15's Avatar
mateoc15 mateoc15 is offline
C A R D S
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2004
Location: The 'Ville
Posts: 773 mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level)mateoc15 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 9 h 10 m 50 sec
Reputation Power: 13
I'm no expert by far, but you could create a stored procedure using whatever SQL commands you have tried, that would allow it to be run whenever. Or you could even make a trigger, if the update needs to happen on firing of a certain event.

Just some thoughts, probably not all that helpful...

Reply With Quote
  #3  
Old March 30th, 2004, 05:49 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,344 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 5 Days 8 h 26 m 34 sec
Reputation Power: 891
how many id numbers are actually in use in each table?

e.g. lowest id=1, highest id=67453

what this would show is that the ids are all under 100000

thus, in a SELECT statement, you could add 100000 to the ids of the first table, in another select you could add 200000 to the ids of the second table, etc.

then you can INSERT/SELECT all 12 query results together into a consolidated table, and none of the id numbers will collide
__________________
r937.com | rudy.ca

Reply With Quote
  #4  
Old March 31st, 2004, 11:45 AM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
you could create the New Database

insert the first set of table in
for the second set and after just do a Insert with a where like this

insert (col1,col2)
select col1,col2
from tb_2
where tb_2.col1 not in (select Col1 from tb_new_all )

this way you'll only insert those record that are not already in the table

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Merge 12 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 1 hosted by Hostway