The ENUM and SET Types
2010-10-28 13:29
381 查看
The ENUM Type
An ENUM is a string object with a value chosen from a list of permitted values that are enumerated explicitly in the column specification at table creation time.Sometimes you can use an ENUM column instead of conventional string types.
An enumeration value must be a quoted string literal; it may not be an expression, even one that evaluates to a string value.
If you wish to use a number as an enumeration value, you must enclose it in quotation marks. It is not advisable to define an ENUM column with enumeration values that look like numbers, because this can easily become confusing.
Duplicate values in the definition cause a warning, or an error if strict SQL mode is enabled.
Each enumeration value has an index. Values from the list of permissible elements in the column specification are numbered beginning with 1.
When retrieved, values stored into an ENUM column are displayed using the letter case that was used in the column definition.
If an ENUM column is declared to permit NULL, the NULL value is a legal value for the column, and the default value is NULL. If an ENUM column is declared NOT NULL, its default value is the first element of the list of permitted values.
ENUM field sorts by the internal integer values, not by the strings themselves. You can also use ORDER BY CAST(col AS CHAR) or ORDER BY CONCAT(col) to make sure that the column is sorted lexically rather than by index number.
The biggest downside of ENUM is that the list of strings is fixed, and adding or removing strings requires the use of ALTER TABLE.
The ENUM and SET types are generally a poor choice for identifiers, though they are appropriate for holding information such as an order’s status, a product’s type, or a person’s gender.
If you want to determine all possible values for an
ENUMcolumn:
SHOW COLUMNS FROM tbl_name LIKE enum_col
The SET Type
.csharpcode, .csharpcode pre{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
li {
list-style-type: disc;
}
相关文章推荐
- Codeforces div.2 B. The Child and Set
- 新建了个用户 结果还sudo报错:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Configuring the Character Set and Collation for Applications
- What is the difference between SET and SELECT when assigning values to variables, in T-SQL?
- Codeforces Round #430 (Div. 2) C Ilya And The Tree SET暴力
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- MOSS 2007 Publishing web site definition template – onet.xml – syntax for properties and getting the right content types
- How to get and set the drawing order of layers in globe(获取并设置Globe图层的叠加次序:)
- Linux下安装oracle数据库提示DISPLAY not set. Please set the DISPLAY and try again.解决方法
- CentOS7 通过VNC 下安装oracle数据库提示DISPLAY not set. Please set the DISPLAY and try again.解决方法
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- 问题:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Highcharts set the min height for (column-stacked-and-grouped) chart.
- Codeforces437 B. The Child and Set
- One or more breakpoints cannot be set and have been disabled!Execution will stop at the beginning of the program
- When the RTP port is set to 8005, why is 8006 used by RTP and 8007 for RTCP for all communications ?
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree dfs+set
- sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- Styling Alert controls in Flex using the StyleManager class and setStyle() methods
- Given a set of n symbols a size k and a combination of length k of non repeating characters from the symbol set