Lookup Tables Best Practices: DB Tables… or Enumerations

后端 未结 9 1823
忘掉有多难
忘掉有多难 2020-12-07 09:27

If we have to store the available positions at a company (i.e. Manager, Team Lead, ... etc). What are the best practices for storing it? I have two opinions with comments...

9条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 09:49

    Option 1: Storing it as DB table with columns ID and Name, and deal with it using queries and joins is the minimum that you should do.

    From "Five Simple Database Design Errors You Should Avoid":

    While application-enforced integrity is sometimes favored by developers, it remains true that the DBMS must still be the centralized enforcer of all integrity.

    The recommended best practice is to implement your database as if it knows nothing about the user interface. That is, the database should enforce all rules pertaining to the data; in this case, the database should be enforcing what values are appropriate. To enumerate what values are appropriate, a lookup table for each type of lookup value is usually the way to go. Many times, applications come and go, yet the database remains and is reused.

    If you want to enforce enumerations in the application, you can certainly do so, but whatever you do, make sure the database does its job as a database and maintains the integrity of the data. If it's troublesome, go through the trouble; you are laying the groundwork. In "Database Design and the Leaning Tower of Pisa," the writer emphasizes why laying the groundwork properly in a database is so very important.

    I hope this helps.

提交回复
热议问题