• Set集合类型是字符类型,可以含有0个或多个值,其中的每个值都需要是在创建字段时指定的集合中
• 比如一个字段被指定为SET(‘one’, ‘two’) not null可以含有以下四种值
• ''
• 'one'
• 'two'
• 'one,two‘
• Set集合最大可以有255个值
• MySQL在存储set集合时,同样也是存储为数字类型
mysql> CREATE TABLE myset (col SET('a', 'b', 'c', 'd')); Query OK, 0 rows affected (0.12 sec) mysql> insert into myset values('a'); Query OK, 1 row affected (0.10 sec) mysql> insert into myset values('a,b'); Query OK, 1 row affected (0.03 sec) mysql> insert into myset values('a,d'); Query OK, 1 row affected (0.01 sec) mysql> insert into myset values('a,bd'); ERROR 1265 (01000): Data truncated for column 'col' at row 1 mysql> insert into myset values('a,b,d'); Query OK, 1 row affected (0.05 sec) mysql> insert into myset values('a,e'); ERROR 1265 (01000): Data truncated for column 'col' at row 1 mysql> select * from myset; +-------+ | col | +-------+ | a | | a,b | | a,d | | a,b,d | +-------+ 4 rows in set (0.00 sec) mysql> insert into myset values('d,a'); Query OK, 1 row affected (0.08 sec) mysql> select * from myset; +-------+ | col | +-------+ | a | | a,b | | a,d | | a,b,d | | a,d | +-------+ 5 rows in set (0.00 sec)