何时在关系数据库中使用枚举或小表? [英] When to use an enum or a small table in a relational database?

查看:126
本文介绍了何时在关系数据库中使用枚举或小表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有几个小实体,我表示为两个列:id和name的小表。



我应该创建一个枚举类型,而不管这些实体的名称不重要吗?

解决方案

讨厌用一个问题回答一个问题,但这取决于。您多久期望值更改,以及您多久发布一次代码?



枚举类型将需要更改代码。纯数据库表将更容易更改。枚举类型对编码来说更为方便。



对于不常见的版本,或者如果您经常有新的/删除/更改的值,请使用数据库表。对于静态值集,或者一直释放代码,请使用枚举。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆