开发者

To use or not to use ENUM/SET type?

开发者 https://www.devze.com 2023-03-27 11:54 出处:网络
Are you using ENUM/SET field type in your projects or you\'re using VARCHAR/INT field and definening available values in code? What is the best practice?

Are you using ENUM/SET field type in your projects or you're using VARCHAR/INT field and definening available values in code? What is the best practice?

Avoiding ENUM/SET seems to me be more easy to maintain, because we have to change values only in code (not both DB and code).

开发者_开发问答Thank you.


Its impossible to answer this question without knowing what your project is, what your data is like, etc.

Generally speaking, its limiting to use ENUM and also limiting to define the values directly in your code. If you need to make a change to either of these if requires "ALTERing" a column or editing your code. If you create a separate table to store acceptable values, and link to that table using a foreign key, you can easily add and edit attributes without having to change any of your definitions or your code.

EDIT: It also makes attributes accessible to your code.


I use enum, but for search/performance, it's better to use INT

0

精彩评论

暂无评论...
验证码 换一张
取 消