Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>No, a foreign key constraint always references exactly one parent table.</p> <p>This question comes up frequently. Here are some of my past answers to it:</p> <ul> <li><a href="https://stackoverflow.com/questions/922184/why-can-you-not-have-a-foreign-key-in-a-polymorphic-association/922341#922341">Why can you not have a foreign key in a polymorphic association? </a> </li> <li><a href="https://stackoverflow.com/questions/441001/possible-to-do-a-mysql-foreign-key-to-one-of-two-possible-tables/441111#441111">Possible to do a MySQL foreign key to one of two possible tables?</a> </li> <li><a href="https://stackoverflow.com/questions/759008/referencing-foreign-keys-in-the-same-column/759100#759100">Referencing foreign keys in the same column</a> </li> <li><a href="https://stackoverflow.com/questions/987654/in-a-stackoverflow-clone-what-relationship-should-a-comments-table-have-to-quest/987709#987709">In a StackOverflow clone, what relationship should a Comments table have to Questions and Answers?</a> </li> <li><a href="https://stackoverflow.com/questions/2002985/mysql-conditional-foreign-key-constraints/2003042#2003042">MySQL - Conditional Foreign Key Constraints</a> </li> <li><a href="https://stackoverflow.com/questions/2098429/how-to-handle-an-or-relationship-in-an-erd-table-design/2098477#2098477">How to handle an “OR” relationship in an ERD (table) design?</a> </li> <li><a href="https://stackoverflow.com/questions/3145084/mysql-two-n1-relations-but-not-both-at-once/3145711#3145711">MySQL: Two n:1 relations, but not both at once</a> </li> </ul> <p>For more on Polymorphic Associations, see my presentation <a href="http://www.slideshare.net/billkarwin/practical-object-oriented-models-in-sql" rel="nofollow noreferrer">Practical Object-Oriented Models in SQL</a> or my book, <a href="http://www.pragprog.com/titles/bksqla/sql-antipatterns" rel="nofollow noreferrer">SQL Antipatterns: Avoiding the Pitfalls of Database Programming</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload