I believe everyone has some knowledge about the MySQL field. The following describes the enumeration in the MySQL field. I hope it will be helpful for you to learn about the MySQL field.
Enumeration in the MySQL field:
Mysql> create table meiju (f1 enum ('1', '2', '3', '4', '5', '6 '));
Query OK, 0 rows affected (0.92 sec)
Mysql> desc meiju;
+ ------- + ------------------------------- + ------ + ----- + --------- + ------- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + ------------------------------- + ------ + ----- + --------- + ------- +
| F1 | enum ('1', '2', '3', '4', '5', '6') | YES | NULL |
+ ------- + ------------------------------- + ------ + ----- + --------- + ------- +
Mysql> insert into meiju values (2 );
Mysql> insert into meiju values ("2 ");
Mysql> insert into meiju values ("6 ");
1 2 3 4 5
The content cannot be inserted without serial numbers.
Mysql> insert into meiju values (8 );
ERROR 1265 (01000): Data truncated for column 'f1' at row 1
Mysql> insert into meiju values ("8 ");
ERROR 1265 (01000): Data truncated for column 'f1' at row 1
Mysql> select * from meiju;
+ ------ +
| F1 |
+ ------ +
| 1 |
| 2 |
| 2 |
| 6 |
+ ------ +
Change table
Mysql> alter table meiju modify f1 enum ("a", "B", "c", "d", "e", "f ");
Query OK, 4 rows affected (0.39 sec)
Records: 4 Duplicates: 0 Warnings: 0
The record can be automatically matched with the new field value when the serial number (amazing)
Mysql> select * from meiju;
+ ------ +
| F1 |
+ ------ +
| A |
| B |
| B |
| F |
+ ------ +
One record can only have one enumerated value, unlike set.
Mysql> insert into meiju values (7 );
ERROR 1265 (01000): Data truncated for column 'f1' at row 1
Note that the value should be enclosed in quotation marks. Otherwise, it should be processed as a serial number.
When the number with quotation marks does not meet the enumeration requirements, it is not appropriate to use it as the serial number.
For example, insert into meiju values ("7 ");
7. If 7th values are not included in the enumerated values, if no seven values exist, an error is returned.
Differences between set and enumeration
1. The set can have 64 values, and 65535 can be enumerated.
2. The serial number of the set is 1 2 4 8 16 enumeration is 1 2 3 4 5 6
3. A set of Field Values can have several values.
+ ------- +
| F1 |
+ ------- +
| F, m |
+ ------- +
But only one enumeration can be
Add and delete fields in MySQL
MySQL Field Type
Mysql foreign Key Usage Analysis
How MySQL defines foreign keys
Seven considerations for converting MySQL to Oracle