To use or not to use ENUM/SET type?
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 "ALTER
ing" 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
精彩评论