Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2013

    Unanswered: Create foreign key using composite primary key

    I am trying to create a FK using a composite PK and here are the details that I want to achieve.
    Table -A
    Column A1 not null,
    Column A2 not null
    Primary key (A1, A2).

    Table -B
    Column B1 Primary key.
    Column B2 not null
    FK (B2) References A(A1).

    When I try to do this I am getting some errors. Questions: First of all is this possible? if yes, then how I can create it. Please let me know on the same.


  2. #2
    Join Date
    Nov 2004
    on the wrong server
    Provided Answers: 6
    if you primary key is a composite, so must be your foreign key. I tend to stay away from composite keys.

    ADD CONSTRAINT FK_boo_hoo FOREIGN KEY (blah,blah2) REFERENCES blah(blah,blah2)
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

Tags for this Thread

Posting Permissions

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