set,enum data types are object of string type, where the set can contain up to 64 elements and can be arbitrarily taken to the elements in the collection. An enum is an element that can only be taken to a wood in a collection, containing up to 65,536 elements, that is, set is a multiple choice, and an enum is a single choice.
Here we compare them to each other in the same and different points:
Copy Code code as follows:
Mysql> CREATE TABLE Db_set (
-> Set1 Set (' x ', ' y ', ' z ') not NULL,
-> enum1 enum (' One ', ' two ', ' three ') not NULL);
Query OK, 0 rows affected (0.06 sec)
mysql> desc Db_set;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| Set1 | Set (' x ', ' y ', ' z ') | NO | | NULL | |
| Enum1 | Enum (' One ', ' two ', ' three ') | NO | | NULL | |
+-------+---------------------------+------+-----+---------+-------+
mysql> INSERT into Db_set values (1,3), (1,4), (4,1);
Query OK, 3 rows affected, 1 Warning (0.00 sec)
Records:3 duplicates:0 warnings:1
Mysql> select * from Db_set;
+------+-------+
| Set1 | Enum1 |
+------+-------+
| x | Three |
| x | |
| Z | One |
+------+-------+
3 rows in Set (0.01 sec)
Here we see their output, I was also puzzled later to know:
in a set type for a range beyond what it can represent, it is added using binary:
Set Element
Decimal
Binary system
' X '
1
0001
' Y '
2
0010
' Z '
4
0100
The enum type is out of range that it can represent, with a null value:
enum Element
Index
Null
Null
‘'
0
' One '
1
' Two '
2
' Three '
3
Now, you see.