enum叫枚举类型,他的值范围需要在创建表时通过枚举的方式显性指定。对于255个之内的枚举,需要一个字节存储。超出的就需要两个。
create table `list`(
`id` int(10) not null comment `主键`,
`type` enum(`m`,`f`) default null comment `性别`,
)ENGINE=InnoDB default charest=utf-8;
insert into `list`(type) values ('m'),('f'),('1'),1,('M');
select * from list where type='m';//小写可以查到
select * from list where type='F';//大写也可以
select * from list where type=1;//使用索引下标也可以查询
select * from list where type='1'; //这种方式是错误的,会导致查询不到,失效
注意:enum类型插入时并不区分大小写!查询时也不区分大小写,但是如果使用索引下标查询时,只能使用int类型,string会导致失效。