MySQL data types: int versus enum
I have a number of columns that only need to store a few values (e.g. 0, 1, 2, 3). What 开发者_JS百科datatype should I pick for such a case? I feel like I should pick something like ENUM('0', '1', '2'). Would int be better (despite it being less restrictive)? Should I consider something else (like tinyint)?
EDIT:
Actually, what general advice should I consider when deciding on a data type?
If you want to restrict it to these 3 values, then indeed ENUM might be the best.
If however, there is a possibility that in future, more values might be needed, then TINYINT UNSIGNED is probably a better solution.
Using enum with fixed set is advisable. If you want to extend then it is 'Alter' basically schema change which should be avoided.
Find better idea about choosing datatype
and get comparison of enum with data types
精彩评论