Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    16

    Unanswered: Primary and foreign keys.

    Hello,
    I have two tables the Main table and the Child table.
    The Main table has primary keys and thye child table has the foreign keys refering to the primary keys of the Main table.
    Can I make the foreign keys as the primary keys also in the Child table?
    Or only the foreign keys ias enough.

  2. #2
    Join Date
    Jul 2006
    Location
    Bangalore
    Posts
    57
    if you make foreign key in your child table as primary key then you will loose integrity of your data because you can insert different data in your primary table as well as child table.
    But if you define foreign key in your child table that mean you are ensuring that no other data except the primary key (in your main table) has can be inserted into foreign key (in your child table).

    Now decision is your, what way you want to implement.
    Last edited by singhipst; 07-11-11 at 07:32.
    Ritesh Kumar Singh
    IBM Certified DB2 DBA for LUW
    **Knowledge Is Theft If Not Shared !!**

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    Quote Originally Posted by pratikp.vasani View Post
    Hello,
    I have two tables the Main table and the Child table.
    The Main table has primary keys and thye child table has the foreign keys refering to the primary keys of the Main table.
    Can I make the foreign keys as the primary keys also in the Child table?
    Or only the foreign keys ias enough.
    Yes, you can do that, but the question is why do you have two different tables with the same PK? If you are doing that for some extreme performance requirement then it might be OK, but it is not 3rd normal form.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •