atkayla
atkayla

Reputation: 8839

Lookup tables - should I use an id column or just use the value?

I have many lookup tables that look like:

id(pk) type(unique)
---
1 UNIVERSITY OF ARIZONA
2 UNIVERSITY OF MIAMI
3 TOKYO UNIVERSITY

Let's say type is a unique string in all cases.

I am questioning whether I should use the id(pk) or just do:

type(pk)
----
UNIVERSITY OF ARIZONA
...

Upvotes: 3

Views: 1844

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269623

You should use the primary key. Here are some reasons:

  • Integers are generally more efficient than strings for joins.
  • Integers are definitely more efficient from a storage perspective -- the strings are longer than the numbers.
  • You might want to change the name one day, say, 'UNIVERSITY OF ARIZONA (TUCSON)'.
  • Primary keys are really what is expected for the foreign key relationship.

Upvotes: 6

Related Questions