页次: 1
示例
mysql> create table tb_enum( e enum('a', 'b', 'c' )); Query OK, 0 rows affected (0.40 sec) mysql> desc tb_enum; +-------+-------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------------+------+-----+---------+-------+ | e | enum('a','b','c') | YES | | NULL | | +-------+-------------------+------+-----+---------+-------+ 1 row in set (0.21 sec) mysql> select e+0 from tb_enum; Empty set (0.04 sec) mysql> insert into tb_enum values ('a'), ('b'), ('c'); Query OK, 3 rows affected (0.03 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> insert into tb_enum values ('d'); Query OK, 1 row affected, 1 warning (0.03 sec) mysql> select * from tb_enum; +------+ | e | +------+ | a | | b | | c | | | +------+ 4 rows in set (0.00 sec) mysql> select e+0 from tb_enum; +------+ | e+0 | +------+ | 1 | | 2 | | 3 | | 0 | +------+ 4 rows in set (0.02 sec) mysql>
枚举类型看上去和字符串有点类似。
枚举类型的特点:
第一: 枚举是有限制的,最对65535 个
第二: 枚举的值都一个索引的值, 这里可以通过 下面语句 可以产看到
mysql> select e+0 from tb_enum;
第三: 如果插入的值,不存在自动转换为空的。 枚举索引的值是0
ipbbs.net
离线
页次: 1