DBAsupport.com Forums - Powered by vBulletin
Results 1 to 4 of 4

Thread: populate primary keys

  1. #1
    Join Date
    May 2005
    Location
    Boracay
    Posts
    681

    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

  2. #2
    Join Date
    May 2005
    Location
    Boracay
    Posts
    681
    hey davey,....do u understand my questions above?

  3. #3
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    Quote 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.

  4. #4
    Join Date
    May 2005
    Location
    Boracay
    Posts
    681
    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
  •  


Click Here to Expand Forum to Full Width