MySQL tutorial SQL enum data type INSERT, UPDATE, delete operation
The enum column always has 1 default values. If you do not specify a default value, the default value is NULL for columns that contain NULL, otherwise the 1th enumeration value will be treated as the default.
If an incorrect value is inserted in the enum column, or if you force the value to be inserted into the enum column using Ignore, it is set to the reserved enumeration value 0, which is displayed as an empty string for the string case.
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 assign "A,x,b,y", the result is "a,b".
Assumption table: There is a field in XXX The folder type 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 ';
The enum type is defined so that the operation is the same as a string. Only when the MySQL process is done with plastic. Much faster than manipulating strings.
Look at an example
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 (IDs, address, phone, emails, birthday, sex, m_status, S_name) VALUES (1, ' Regina Street ', 7176666, ' net@hotmail.com ', ' 1971-04-26 ', ' m ', ' y ', ' ane Regina ');
INSERT into Employee_person (IDs, address, phone, email, birthday, sex, m_status, s_name, children) VALUES (2, ' 1232 Albert A road ', 5553312, ' jo@hotmail.com ', ' 1968-03-02 ', ' m ', ' y ', ' Jane van ', 3;