Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
...
like image 432
atkayla Avatar asked Dec 21 '25 09:12

atkayla


1 Answers

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.
like image 181
Gordon Linoff Avatar answered Dec 23 '25 23:12

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!