Author Topic: Can a foreign key reference a unique non-primary key?  (Read 581 times)

0 Members and 1 Guest are viewing this topic.

Offline proudTopic starter

  • Enthusiast
  • Posts: 57
    • View Profile
Can a foreign key reference a unique non-primary key?
« on: February 08, 2010, 08:40:16 AM »
Hello everyone, I have 2 tables: [books] with the fields (id, title,author,isbn) and another table called [book issue] with the fields (id, borrower_id, borrow_date, book_isbn)..
Now the field (book_isbn) in the [book issue] table references (isbn) in the books table, which is a unique field but not a primary key.

My questions:

1- Is it correct for a foreign key to reference a unique but non-primary key in another table?

2- Is it okay for the foreign key field to have a different name than the field it references in the other table?

Your help is indeed appreciated..

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
Re: Can a foreign key reference a unique non-primary key?
« Reply #1 on: February 08, 2010, 08:49:16 AM »
1. Yes
2. Yes


3. I would avoid using ISBN as a field referencing anything in database. I've been working in book publishing business for some time and have seen my sort of fscked up ISBNs along the way.
« Last Edit: February 08, 2010, 08:51:00 AM by Mchl »
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading