Mysql SQL enum Data Type Insert, update, and delete operations

Source: Internet
Author: User
Tags mysql tutorial

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 );

 

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.