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

Thread: Composite Foreign Key Constraints!

  1. #1
    Join Date
    Feb 2001
    Posts
    286
    Hi all!

    Query!:

    1.I have tables BR_Header and BR_details wherein I have
    composite Primary key(company_code,Br_NO) belonging to
    BR_Header Table and Foreign key(company_code,Br_NO) belonging to BR_details table.Where BR means Bank Receipts.

    Now whenever I define foreign Key constraints on BR_details table as Foreign Key(Br_NO),error message flashes saying that no unique or primary key match found.

    On the other hand,Composite Foreign Key(company_code,Br_NO) is accepted and says TABLE ALTERED.

    Why Oracle doesn't accept constraint Foreign key(Br_NO) defined on Br_details Table compared to constraint Primary Key(company_code,Br_NO).

    P.S:On the Br_details Tables,Composite primary Key(Company_code,Br_NO) is also defined wherein the purpose is to define constraint Foreign Key(Br_NO) on the BR_details Table referencing Constraint Primary Key(Company_Code,Br_No)!

    Regards,

    Amitstora.


  2. #2
    Join Date
    Nov 2000
    Location
    Baltimore, MD USA
    Posts
    1,339
    I'm not sure I fully understand the question. It's like asking why a numeric field cannot accept characters.

    If table1 has a PK Col1, Col2 - Table2 cannot have an FK to only Col2. It wouldn't make any sense to do that. I'm not sure what you would expect it to do, but it is not allowed because it would simply be wrong.

    An FK must point to the entire PK - that's the law

    Why is the PK of BR_Header composite anyway? It would seem as if BR_No would be unique for the receipt, no?

    - Chris

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