Set & amp; enum Summary (database), setup

Source: Internet
Author: User

Set & enum Summary (database), setup

Today, we found that mysql has the set data type, which is also used in business operations. After checking the information online, let's make a summary.

Summarize the differences between the two.

Set and enum are multiple-choice and single-choice in similar forms. set and enum are represented by integers in the database and can be displayed as strings (avoid using numeric strings)

The two types of APIs are described as follows:

 

There is a limit on the number of data of the two types, and 2 ^ 64 = 65536, so it is estimated that it has something to do with the computer hardware. Currently, the computer has 64-bit computers, and there are no 128-bit computers.

 

How does one implement multiple options in set? I did some tests myself, as shown below:

Create a new TABLE db_set with the set and enum columns and compare the DROP table if EXISTS db_set; create TABLE db_set (id int AUTO_INCREMENT primaryset1 set ('x', 'y', 'z ') not null, enum1 enum ('one', 'two', 'three ') not null); insert several pieces of data in integer form, because the two types of data are expressed in integer form internally, insert the numeric value into db_set (set1, enum1) values ), (), (); SELECT * FROM db_set; the result is as follows:

 

As you can see, set is mapped by binary BITs, which explains why set only supports a maximum of 64 values (null value is not counted.

 

 

 

 

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.