When to use an enum or a small table in a relational database?

database, enums, sql

Solution

Hate to answer a question with a question, but it depends. How often do you expect the values to change, and how often do you release code?

Enum types will require a code change. A pure database table will be much easier to change. Enum types are more convenient for coding.

For infrequent releases, or if you often have new/deleted/changed values, use a database table. For static sets of values, or if you release code all the time, use an enum.

Problem

I have a several small entities in my database that I represent as small table with two columns: id and name. Example of such entities: countries, continent. Should I create an enum type instead, whenever the name of those entities doesn't matter?

Original source