MySQL SQL enum data type INSERT, UPDATE, delete operation

Source: Internet
Author: User
Tags mysql tutorial

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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.