1,enum
mysql> create table enumDemo(gender enum('M', 'F'));
Query OK, 0 rows affected (0.02 sec)
mysql> desc enumDemo;
+--------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+---------------+------+-----+---------+-------+
| gender | enum('M','F') | YES | | NULL | |
+--------+---------------+------+-----+---------+-------+
1 row in set (0.01 sec)
mysql> insert into enumDemo values('M'),('1'),('f'),(NULL);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from enumDemo;
+--------+
| gender |
+--------+
| M |
| M |
| F |
| NULL |
+--------+
4 rows in set (0.00 sec)
2, set
mysql> create table setDemo(col set('a', 'b', 'c', 'd'));
Query OK, 0 rows affected (0.02 sec)
mysql> desc setDemo;
+-------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+-------+
| col | set('a','b','c','d') | YES | | NULL | |
+-------+----------------------+------+-----+---------+-------+
1 row in set (0.00 sec)
mysql> insert into setDemo values('a', 'b', 'c'), ('a', 'b', 'c', 'd'), ('a', 'b');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into setDemo values('a', 'b', 'c'), ('a', 'b', 'c', 'd'), ('a', 'b');
ERROR 1136 (21S01): Column count doesn't match value count at row 1
mysql> insert into setDemo values('a,b,c'), ('a,b'), ('a,b,v,c');
ERROR 1265 (01000): Data truncated for column 'col' at row 3
mysql> insert into setDemo values('a,b,c'), ('a,b'), ('a,b,c,c');
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from setDemo;
+-------+
| col |
+-------+
| a,b,c |
| a,b |
| a,b,c |
+-------+
3 rows in set (0.00 sec)
enum枚举插入时只能插入枚举中的一个,并且当插入的值不在枚举值中,默认插入第一个枚举值,set插入时,可以插入set集合中的任意值,重复的值不会多次插入;