码迷,mamicode.com
首页 > 数据库 > 详细

8.3.4 - mysql 枚举,

时间:2018-03-13 01:14:39      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:class   run   操作   类型   col   范围   ror   consumer   vip   

枚举类型与集合类型

字段的值只能在给定范围中选择,如单选框,多选框

enum 单选 只能在给定的范围内选一个值,如性别 sex 男male/女female

set 多选 在给定的范围内可以选择一个或一个以上的值(爱好1,爱好2,爱好3...)

create table consumer(
 id int,
 name char(16), 
 sex enum(male,female),
 level enum (vip1,vip2,vip3),
 hobbies set(play,music,run)
);

insert into consumer values
(1,cmz,male,vip1,music,run);

# 因为不在选择范围内会报错
insert into consumer values
(2,cmz,xxx,vip1,music,run); 
# 操作过程
mysql> create table consumer(
    ->  id int,
    ->  name char(16), 
    ->  sex enum(male,female),
    ->  level enum (vip1,vip2,vip3),
    ->  hobbies set(play,music,run)
    -> );
Query OK, 0 rows affected (0.03 sec)

mysql> insert into consumer values
    -> (1,cmz,male,vip1,music,run);
Query OK, 1 row affected (0.04 sec)
mysql> select * from consumer;
+------+------+------+-------+-----------+
| id   | name | sex  | level | hobbies   |
+------+------+------+-------+-----------+
|    1 | cmz  | male | vip1  | music,run |
+------+------+------+-------+-----------+
1 row in set (0.00 sec)

mysql> insert into consumer values
    -> (1,cmz,xxx,vip1,music,run);
ERROR 1265 (01000): Data truncated for column sex at row 1

 

8.3.4 - mysql 枚举,

标签:class   run   操作   类型   col   范围   ror   consumer   vip   

原文地址:https://www.cnblogs.com/caimengzhi/p/8552508.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!