何时在关系数据库中使用枚举或小表? [英] When to use an enum or a small table in a relational database?
问题描述
我应该创建一个枚举类型,而不管这些实体的名称不重要吗?
讨厌用一个问题回答一个问题,但这取决于。您多久期望值更改,以及您多久发布一次代码?
枚举类型将需要更改代码。纯数据库表将更容易更改。枚举类型对编码来说更为方便。
对于不常见的版本,或者如果您经常有新的/删除/更改的值,请使用数据库表。对于静态值集,或者一直释放代码,请使用枚举。
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?
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.
这篇关于何时在关系数据库中使用枚举或小表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!