enum设置后
值只能是给出的值中的其中一个
mysql> create table enum(e enum('1','2','3','4','5','6','7','8','9','10'));
Query OK, 0 rows affected (0.03 sec)
mysql> desc enum;
+-------+------------------------------------------------+------+-----+---------
+-------+
| Field | Type | Null | Key | Default
| Extra |
+-------+------------------------------------------------+------+-----+---------
+-------+
| e | enum('1','2','3','4','5','6','7','8','9','10') | YES | | NULL
| |
+-------+------------------------------------------------+------+-----+---------
+-------+
1 row in set (0.00 sec)
mysql> insert into enum values(1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into enum values(11);
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> select * from enum;
+------+
| e |
+------+
| 1 |
| |
+------+
2 rows in set (0.00 sec)
mysql> insert into enum values(8);
Query OK, 1 row affected (0.00 sec)
mysql> select * from enum;
+------+
| e |
+------+
| 1 |
| |
| 8 |
+------+
3 rows in set (0.00 sec)
mysql>
当值 不存在enum中时, 会返回默认的值 , 也就是default中的值。
mysql> create table enum1(e enum('1','2','3','4','5','6','7','8','9','10') not n
ull default '11');
ERROR 1067 (42000): Invalid default value for 'e'
mysql> create table enum1(e enum('1','2','3','4','5','6','7','8','9','10') not n
ull default 10);
Query OK, 0 rows affected (0.03 sec)
mysql> desc enum1;
+-------+------------------------------------------------+------+-----+---------
+-------+
| Field | Type | Null | Key | Default
| Extra |
+-------+------------------------------------------------+------+-----+---------
+-------+
| e | enum('1','2','3','4','5','6','7','8','9','10') | NO | | 10
| |
+-------+------------------------------------------------+------+-----+---------
+-------+
1 row in set (0.00 sec)
mysql>