Mysql tutorial SQL enum Data Type Insert, update, delete operations
The enum column always has one default value. If the default value is not specified, the default value is null for columns that contain null. Otherwise, the 1st enumerated values are treated as the default value.
If an incorrect value is inserted in the enum column, or if ignore is used to forcibly insert the value into the enum column, it is set to the reserved enumerated value 0. In the case of a string, it is displayed as a null string.
If an incorrect value is inserted in the set column, the value is ignored. For example, if a column can contain values "a", "B", and "c", and assigned values "a, x, B, and y", the result is "a, B ".
Assume that the folder type of the field in xxx is enum ('inbox', 'Outbox', 'other ')
Save
Insert into 'xxx' ('folder') values ('inbox ');
Insert into 'xxx' ('folder') values ('Outbox ');
Insert into 'xxx' ('folder') values ('other ');
Update
Update 'xxx' set 'folder' = 'inbox ';
Update 'xxx' set 'folder' = 'Outbox ';
Update 'xxx' set 'folder' = 'other ';
Delete
Delete from 'xxx' where 'folder' = 'inbox ';
Delete from 'xxx' where 'folder' = 'Outbox ';
Delete from 'xxx' where 'folder' = 'other ';
After the enum type is defined, the operation will be the same as the string. It is only faster than the operation string that mysql uses for integer operation.
View instances
Create table employee_person (
Id int unsigned not null primary key,
Address varchar (60 ),
Phone int,
Email varchar (60 ),
Birthday date,
Sex enum ('M', 'F '),
M_status enum ('y', 'n '),
S_name varchar (40 ),
Children int
);
Insert into employee_person (id, address, phone, email, birthday, sex, m_status, s_name) values (1, '2017, regina street ', 200, 'net @ hotmail.com ', '2017-04-26', 'M', 'y', 'ane regina ');
Insert into employee_person (id, address, phone, email, birthday, sex, m_status, s_name, children) values (2, '1996, 1232, 5553312, 'jo @ hotmail.com ', '2017-03-02 ', 'M', 'y', 'Jane van', 3 );