5

What is the name for the technique of using a set of foreign keys in a table where all but one are NULL for a given row?

In other words, each row needs a foreign key to one (and only one) of n different possible tables so you actually have all the necessary foreign keys but all but one are NULL.

(users of Django may recognize this as an alternative to using a Generic Foreign Key)

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
James Tauber
  • 3,386
  • 6
  • 27
  • 37

2 Answers2

6

The term for the design you're describing is Exclusive Arc.

Instead, I prefer to make one foreign key that references a common super-table of your n different parent tables.

See my other answers for polymorphic associations:

Community
  • 1
  • 1
Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
2

It would have been easier with a example, but a common way to untangle this is simply to find a common super-type for those tables. Suppose that we have tables Book, Article, Magazine and now a table has to have foreign key to these tables. Using a common super-type Publicationresolves this. See here for the model and the similar question/answer.

Community
  • 1
  • 1
Damir Sudarevic
  • 21,891
  • 3
  • 47
  • 71