Home » SQL & PL/SQL » SQL & PL/SQL » primary and foreign keys problem
primary and foreign keys problem [message #184501] Wed, 26 July 2006 16:53 Go to next message
Messages: 68
Registered: September 2004
I want to thank you all for your input. Actually I should apoligize because I haven't defined the problem area as I should.

The issue here is that data is already in the destination tables. The staging tables are mutations. So, In A way I have to use the primary and foreign keys to find the related records using the primary keys on the staging tables to update the destination tables.

So, what I need to do is (I think), check if the supplied primary keys are unique and find the FK's.

Does anyone know how to accomplish this?

Thanks in advance.


I have text files which I process with sqlloader into staging tables. This is done and the staging tables are filled. There are no relations between the staging tables. The data in the staging tables should be processed and insert into the destination tables. However, on the destination side, there is ofcourse relationship between the tables. I need to get the data from the staging tables and insert it into the destination tables.

I know which table I should process first and second and go on.
How can I properly use the foreign keys and primary keys to get the related data from the staging tables and insert these into the destination tables without getting constraint errors because of parent-child relations?

Can anyone please help me out with ideas?
I am thinking about looping through the tables, finding the related tables on the destination side, check the foreign keys and primary keys, but actually I'm not pretty sure about how to accomplish this.

I really do hope that someone can help me out!

Thanks in advance


[Updated on: Thu, 27 July 2006 09:08]

Report message to a moderator

Re: primary and foreign keys problem [message #184519 is a reply to message #184501] Wed, 26 July 2006 19:47 Go to previous messageGo to next message
Messages: 2
Registered: July 2006
Location: California
Junior Member
Since the schema is unknown just give a try...

Better have a good understanding about the destination tables and columns. Match them with the staging tables.Use constraints in staging tables and start inserting. Hope this works out.
Re: primary and foreign keys problem [message #184521 is a reply to message #184501] Wed, 26 July 2006 21:20 Go to previous messageGo to next message
Messages: 35
Registered: March 2006
Location: London

If the inserted data does not violate constraint rules.

Then first disable the constraints and start entering the data, but make sure you keep track of the data being entered.

and then enable the constraints.

hope this should work.

Re: primary and foreign keys problem [message #184563 is a reply to message #184521] Thu, 27 July 2006 01:24 Go to previous message
Messages: 20848
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Perhaps you might want to read more about deferred constraint checking which enables you to check whether it is satisfied on commit (and not on insert). See also this document (search for "Specifying Constraint State").
Next Topic: Display images stored in blob
Goto Forum:

Current Time: Fri Oct 21 12:34:14 CDT 2016

Total time taken to generate the page: 0.14493 seconds