Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sem or SantaMufasa ... please help

Status
Not open for further replies.

sbix

IS-IT--Management
Nov 19, 2003
493
CA
Hi folks,
I have a little problem.
I am creating a big DB by merging several almost identical DB into one.
The relevant tables have a column which discriminates the DB from which they come (thanks to the original DBA I haven't to be worried about this), but some "almost static" tables haven't this fields because they are almost identical for all the DBs, the difference are in some more or less rows.
I decided to import the biggest of the DBs and then to import table by table of the followings.
The problem is static table's import produces lots of error rows in log file which are difficult to analyze in order to find a real error.
To avoid this problem I decided to create another user, to import those static tables from in this schema and then to insert the difference between the MAIN tables and these "PARKING" ones. Subsequently to TRUNCATE the parking tables in order to populate them with the data of another DB and repeat the operation.
So the question is:
Is the sql statement to use to insert the difference something like:

insert into MAIN_USER.MAIN_TABLE
(select * from SCRATCH_USER.SCRATCH_TABLE
minus
select * from MAIN_USER.MAIN_TABLE);

 
If both tables has similar structures your statement is valid. Have you got any errors?

P.S. I'd suggest you to use more descriptive subject line in the future.

Regards, Dima
 
Thanks dima,
ooooops ... I haven't been much detailed!!!
There's a little problem:
These tables have primary keys, but ... because of some little bug in the application, for the same primary key of the same table coming from 2 different DBs could be a different record.
The logic to apply should be "The first who arrives wins" ... so the data imported with IMP at the first time, in the MAIN_USER.MAIN_TABLE are the winners ....
How do I to modify the script?
 
Something like

insert into MAIN_USER.MAIN_TABLE
select * from SCRATCH_USER.SCRATCH_TABLE
where pk_field in
(select pk_field from SCRATCH_USER.SCRATCH_TABLE
minus
select pk_field from MAIN_USER.MAIN_TABLE);

Though I must say that I'm not completely understand your task: do you need to preserv PK fields or real content?

Regards, Dima
 
No, I have to preserve the "FIRST CONTENT" inserted in the main table, regardless it's the right one or not.
If between all DBs for those specific tables there are some rows with identical PK but with different values in the other fields, by the moment nobody can say which is the right one, the customer agreed with the solution "The first who arrives wins" ... :)))
(Which is not very professional but ...)

Thanks a lot dima!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top