Database – DB Enumerations vs App Enumerations vs Lookup tables

databasedatabase-designenumpostgresrelational-database

We started a project recently, and during the design process, we have some arguments among team members. We have to deal with enumerations so we ended up with three choices.

  1. Have the enumerations as Normal Enums in Database
  2. Have the enumerations inside the Application and isolated from the Database. Keep them only in App level.
  3. Store the enumerations in different tables in the DB

What do you think and why?
From my experience, I choose the 3rd, as I 've never seen that the cost of joins is really an issue. And if you use an ORM then the cost of joins is almost nothing due to caching.

Best Answer

There is a dichotomy between two opposing viewpoints

  1. Do you want the ability to add new items to the set without recompiling the application - this favours a lookup table in the database.
  2. Is there any business logic based on the set within the compiled application. e.g.

    if (Client.ClientType == ClientType.Important)
        DoSomethingSpecial();
    

    This favours an enum within the application.

You have to decide which is most important to your case. Having both a lookup table and an enum, might seem like belt and braces security, but can soon cause issues if they get out of step.