If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Primary Key & Foreign Key Problem

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-19-10, 14:07
Kiada Kiada is offline
Registered User
 
Join Date: Mar 2010
Posts: 7
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
Reply With Quote
  #2 (permalink)  
Old 03-19-10, 14:16
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,085
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


__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-19-10, 14:18
Kiada Kiada is offline
Registered User
 
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!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On