MySQL中的enum类型有什么优点?
天蓬老师
天蓬老师 2017-04-17 16:20:15
0
4
635

刚开始用MYSQL,一直没注意到这个类型,它有什么优点?或者说如果存储内容都是短字符串的话,它跟varchar有何区别?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(4)
左手右手慢动作

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

The 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...🎜
Peter_Zhu

The advantage of Enum is that the value can be within several value ranges

PHPzhong

The speed of querying string and enum is almost the same. It is logical to use enum or set. . .

伊谢尔伦

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template