Question

  Asked: Apr 8 2008   1:04 PM GMT
  Asked by: Rwy


Oracle Application Express Item


Primary keys, Foreign keys, Oracle, Database

I have two tables with parent-child relationship. Is there a way to automatically populate the foreign key field of the child table with the exact data from the primary key of the parent table?

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



This depends upon the primary key of the child table. If a record already exists in the child table with the given foreign key value and the parent record is updated, then a "post update trigger" on the parent table can be written to update the foreign key value of the child table. All key values of the child table must be available to ensure you update the correct row.

If a new record is inserted into the parent table with a new key value, then it would be necessary to have a "post insert trigger" on the parent table to create a new record in the child with the new value. But, this would not work properly unless all non-null and primary key column values were available to insert a new record into the child table.

So, the short answer to your question is "yes, if you have the right information available."
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Database and Oracle.

Looking for relevant Database Whitepapers? Visit the SearchOracle.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register