刚开始用MYSQL,一直没注意到这个类型,它有什么优点?或者说如果存储内容都是短字符串的话,它跟varchar有何区别?
ringa_lee2017-04-17 16:22:15
For example, the following two fields:
name varchar(50) ,
sex enum('male' , 'female' , 'both' , 'unknow')
The name
field can be inserted into any string. name
字段可以插入任意字符串。
sex
字段只允许插入 male , female , both , unknow
中的其中之一,不在范围内的值会报错。
enum
相比较 varchar
sex
field only allows one of male, female, both, unknown
to be inserted. Values that are not within the range will report an error.
enum
is more standardized compared to varchar
, and you can also limit it in the program. 🎜
🎜For performance comparison, I have to wait for the experts to answer...🎜天蓬老师2017-04-17 16:22:15
The advantage of Enum is that the value can be within several value ranges
PHPz2017-04-17 16:22:15
The speed of querying string and enum is almost the same. It is logical to use enum or set. . .
伊谢尔伦2017-04-17 16:22:15
The underlying storage method of enum is integer type
For example, such a field
sex enum('male', 'female', 'both', 'unknow')
When querying
where sex='male'
and where sex=1 are equivalent