-
populate primary keys
Hi Friends,
I am practising developing and application.
I am just confused about the autogenerated primary-key ID
in a certain table, and how to populated it to the corresponding
child table. It is like this:
A. Parent Table.
I got an employee table EMP (emp_id, name)
with primary key emp_id , auto generated by a trigger.
B. Child Table.
I got a 2nd table EMP_LOANS (loan_id,emp_id,amount)
With foriegn key emp_id renferences EMP.emp_id
with primary key loan_id , auto generated by a trigger.
My problem is, when i encode data to the 2 tables, i only
supply the EMP.name and EMP_LOANS.amount because the id's
are auto generated.
So what i see(enterable) in the screen form are just the fields
[name, amount]
How do i pick up the EMP.emp_id and populate it to
EMP_LOANS.emp_id?
Thanks a lot
-
hey davey,....do u understand my questions above?
-
Originally Posted by yxez
How do i pick up the EMP.emp_id and populate it to
EMP_LOANS.emp_id?
That depends on your app. But you cannot expect Oracle to track that value. Assuming that the pkey of the parent table is set using a trigger then use the returning clause on the insert into EMP table in order to use it for the insert into the EMP_LOANS table.
-
Thanks gandy....well, what i did was not to allow the trigger to populate the ID fields....i do select(nextval) it myself in the program
so i can get hold control of it
Last edited by yxez; 09-07-2006 at 12:15 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|