This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes About  foreign key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "About  foreign key" Watch "About  foreign key" New topic
Author

About foreign key

raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 286
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

Joined: Oct 13, 2005
Posts: 43368
    
  32
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

Joined: Oct 13, 2005
Posts: 43368
    
  32
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.
 
Consider Paul's rocket mass heater.
 
subject: About foreign key
 
jQuery in Action, 3rd edition