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.