Introduction to Mysql set and enum _mysql

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.