Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About foreign key

 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
In Head First SQL,on page 304 its written that
Foreign key don't have to be unique -infact they often aren't


on page 305 it says
You can use a foreign key to reference a unique value in the parent table.It doesn't have to be the primary key of the parent table,but it must be unique.


Somebody please clarify about it.

Thanks
Raj
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have one primary key for each address in the address table.
Several people in the person table can live at the same address, using the same value for their foreign key.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my example you could not use town as a foreign key; there are likely to be several addresses for the same town, so you could not retrieve anybody's address.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic