Mysql enumeration type enum and collection type set

Mysql enumeration type and collection type

We first create a database table, here is the creation statement:

create table consumer(
    id int,
    name char(16),
    sex enum('male','female','other'),
    level enum('vip1','vip2','vip3'),
    hobbies set('play','music','read','run')
)

The meaning of enumeration here is that you can only select one from here, and the set of set means that you can select more than one from the set.

Enter the insert statement

insert into consumer values(1,'egon','male','vip2','music,read')

Some people may be curious, what happens if you enter more than one corresponding to the enum?

insert into consumer values(2,'eg','male','vip1,vip2','music,read')

Run, to see the content of the table:
Insert picture description here
you can see that the id is 2 and the level is empty

If there are multiple inputs corresponding to the set:

insert into consumer values(3,'eg','male','vip2','music,read,aaa')

Run and check the table:
Insert picture description here
you can see that hobby is aaa and is not inserted (because it is not in the set when the table was created)

Guess you like

Origin blog.csdn.net/m0_50481455/article/details/114110278