mysql> create table t_col (col set ('a','b','c','d'));
Query OK, 0 rows affected (0.27 sec)
mysql> desc t_col
-> ;
+-------+----------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------------------+------+-----+---------+-------+
| col | set('a','b','c','d') | YES | | NULL | |
+-------+----------------------+------+-----+---------+-------+
1 row in set (0.02 sec)
mysql> show create table t_col\G;
*************************** 1. row ***************************
Table: t_col
Create Table: CREATE TABLE `t_col` (
`col` set('a','b','c','d') DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
1 row in set (0.01 sec)
ERROR:
No query specified
mysql> INSERT INTO T_COL VALUES('a,b'),('a,d,a'),('a,b'),('a,c'),('a');
Query OK, 5 rows affected (0.11 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from t_col;
+------+
| col |
+------+
| a,b |
| a,d |
| a,b |
| a,c |
| a |
+------+
5 rows in set (0.01 sec)
mysql> INSERT INTO T_COL VALUES('a,b'),('a,d,a'),('a,b'),('a,c'),('a'),('a,f');
ERROR 1265 (01000): Data truncated for column 'col' at row 6
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30166976/viewspace-2710442/ ,如需转载,请注明出处,否则将追究法律责任。