Parent-Child Relationship Help(Please!)

  • I've got a problem figuring out how to get a Foreign Key in one table to automatically coinside to the value of its Primary key in another. Here's what I'm getting at:

    Table 1 has a Primary Key of Company_id

    Table 2 has a Primary Key of Office_id and a foreign key of Company_id(related from table 1) Now I can't figure out how to get the FKEY of table2.Company_id to automatically contain the same value as the PKEY table1.Company_id.

    I'm going to be inserting, updating, and deleting records. One company can have many offices but I can't figure out how to get them related. I hope this is enough info for someone to understand my problem. Thanks.

  • Creating the foreign merely requires that the parent key exist before the child can be inserted.

    I can have:

    Company

    CompanyID Company

    --------- -------

    1 ABC

    2 DEF

    Office

    Office ID CompanyID

    --------- ----------

    1 1

    2 1

    Now if I insert Office 3 with company 3, I will get an error. Becuase the FK cannot be satisfied. If I insert Office 3 with company 2, then it works.

    There is no coincide, you have to insert the data in the correct order.

    Steve Jones

    steve@dkranch.net

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply