Enumerating enum types in MySQL detailed

Source: Internet
Author: User

For 255 to 65,535 members, 2 bytes of storage are required. Up to 65,535 members are allowed.
A data table with enumerated types is created first through the SQL statement.

The code is as follows Copy Code
CREATE TABLE User_sex (Sex enum (' M ', ' F '));

Write a few more test data to the table:

INSERT into user_sex values (' M '), (' s '), (' 2 '), (' F ');

When you view the results of a write in a table, the discovery becomes such a m,m,m,f (note that each character is a record). It is known from the result that the enum type is case-insensitive, and that ' F ' is automatically converted to ' F ', forcing the first value (M) to be written to the enumeration when it writes a value that is not in the specified range. In addition, the enum type selects only a single value from the Fill collection and cannot fetch multiple values.

Enum Test Summary

n Enum type enum

a). database table Mysqlops_enum Structure
Execute the SQL statement created by the database table Mysqlops_enum:

Assumption table: There is a field in XXX The folder type is enum (' Inbox ', ' Outbox ', ' other ')

Save

The code is as follows Copy Code

insert INTO ' xxx ' (' folder ') VALUES (' Inbox ');
insert INTO ' xxx ' (' folder ') VALUES (' Outbox ');
insert INTO ' xxx ' (' folder ') VALUES (' other ');

Update

The code is as follows Copy Code

Update ' xxx ' set ' folder ' = ' Inbox ';
Update ' xxx ' set ' folder ' = ' Outbox ';
Update ' xxx ' set ' folder ' = ' other ';

Delete

The code is as follows Copy Code

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 action is the same as a string

For more details please see: http://www.111cn.net/database/mysql/38235.htm

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.