Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2010
    Posts
    7

    Unanswered: Primary Key & Foreign Key Problem

    Hey first post, and beginner at database design so apologies if my question is a bit stupid.

    I've designed a database, but I've got a question about one of the tables.

    Basically the two fields that can uniquely identify a record within this table are both foreign keys to other tables. I've read that you can have two (or more) columns (fields?) as the primary keys (concatenated??).

    Can you have two foreign key fields as two concatenated primary key fields?

    Does every table *need* a primary key?

    Am I talking gibberish? It's all I feel like I'm reading at the moment lol

    Table A
    TableAfield1 (PK)
    TableAfield2

    Table B
    TableBfield1 (PK)
    TableBfield2

    Table C
    TableAfield1 (PK & FK)
    TableBfield1 (PK & FK)
    TableCfield1
    TableCfield2
    etc..

    in Table C --> TableAfield1 & TableBfield1 together uniquely identifies each record, but they're also foreign keys to both Table A and Table B.

    Is this common or purely a design flaw?

    Any help appreciated thanks

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by Kiada View Post
    Can you have two foreign key fields as two concatenated primary key fields?
    yes

    Quote Originally Posted by Kiada View Post
    Does every table *need* a primary key?
    yes (although some people will argue this point -- don't listen to them)

    Quote Originally Posted by Kiada View Post
    Am I talking gibberish?
    nope

    Quote Originally Posted by Kiada View Post
    Is this common or purely a design flaw?
    the former


    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Mar 2010
    Posts
    7
    Thanks for the speedy reply and the help was a bit worried I'd messed my first design up then! Although this alone doesn't mean it isnt messed up but at least this part seemingly works, thanks again!

Posting Permissions

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