# Enumeration And Collection Types
__*ENUM Data Type*__
__*SET DATA TYPE*__
+ Data Type:
  + `ENUM`: Select a single string value from a list of enumerated string values
  + `SET`: Select zero or more string values from a list of string values
+ `ENUM` Examples:
  + `ENUM('Terrestrial', 'Jovian', 'Dwarf')` 
+ `SET` Examples:
  + `SET('nose', 'head', 'eyes')` 
```
tidb> DESC test.sss;
+-------+------------------+------+------+---------+-------+
| Field | Type             | Null | Key  | Default | Extra |
+-------+------------------+------+------+---------+-------+
| id    | ~!@set('A','B','C')@!~ | YES  |      | NULL    |       |
+-------+------------------+------+------+---------+-------+
tidb> INSERT INTO test.sss VALUES ('AAA');
ERROR 1265 (01000): Data truncated for column 'id' at row 1

tidb> INSERT INTO test.sss VALUES (~!@'C,B'@!~);
Query OK, 1 row affected (0.03 sec)
```

------------------------------------------------------------
- ENUM type

- Enumeration type is a string; it can only be a string object with one value. Its value must be selected from a fixed set defined at the time the table is created. The syntax is:
`ENUM('value1','value2',...) [CHARACTER SET charset_name] [COLLATE collation_name]` 
For example:
`ENUM('apple', 'orange', 'pear')` 

- Enumeration type values are stored inside TiDB using numeric values. Each value is converted to a number in the order defined. For example, in the example above, each string value is mapped to a number:

Number of values
NULL NULL
"0
'apple' 1
'orange' 2
'pear' 3


- SET type

- A collection type is a string containing zero or more values, each of which must be selected from a fixed set defined when creating a table. The syntax is:
`SET('value1','value2',...) [CHARACTER SET charset_name] [COLLATE collation_name]` 
For example:
`SET('1', '2') NOT NULL` 
In the example above, the valid values for this column could be:
"
'1'
'2'
'1,2'

- The value of the set type is converted to an Int64 value inside TiDB. Whether or not each element exists is represented by a value of 0/1 in binary bits. For example, in this example SET ('a', 'b', 'c', 'd'), each element is mapped to a number, and the binary representation of each number will only have one digit 1:
  
Member decimal indicates binary representation
'a' 1 0001
'b' 2 0010
'c' 4 0100
'd' 8 1000
Thus, for elements with values of ('a', 'c'), the binary representation is 0101.