ENUM and SET columns provide an efficient way to define columns that can contain only a given set of values. ENUM和SET列提供了一种有效的方法来定义只能包含给定值集的列。See Section 11.3.5, “The ENUM Type”, and Section 11.3.6, “The SET Type”.请参阅第11.3.5节,“ENUM类型”和第11.3.6节,“SET类型”。
Unless strict mode is disabled (not recommended, but see Section 5.1.11, “Server SQL Modes”), the definition of a 除非禁用了严格模式(不建议使用,但请参阅第5.1.11节,“服务器SQL模式”),否则ENUM or SET column acts as a constraint on values entered into the column. An error occurs for values that do not satisfy these conditions:ENUM或SET列的定义将对输入该列的值起约束作用。对于不满足以下条件的值,会发生错误:
An ENUM value must be one of those listed in the column definition, or the internal numeric equivalent thereof. ENUM值必须是列定义中列出的值之一,或其内部等效数字。The value cannot be the error value (that is, 0 or the empty string). 该值不能是错误值(即0或空字符串)。For a column defined as 对于定义为ENUM('a','b','c'), values such as '', 'd', or 'ax' are invalid and are rejected.ENUM('a','b','c')的列,''、'd'或'ax'等值无效,将被拒绝。
A SET value must be the empty string or a value consisting only of the values listed in the column definition separated by commas. For a column defined as SET('a','b','c'), values such as 'd' or 'a,b,c,d' are invalid and are rejected.SET值必须是空字符串或仅由列定义中列出的值组成的值,这些值用逗号分隔。对于定义为SET('a','b','c')的列,'d'或'a,b,c,d'等值无效,将被拒绝。
Errors for invalid values can be suppressed in strict mode if you use 如果使用INSERT IGNORE or UPDATE IGNORE. INSERT IGNORE或UPDATE IGNORE,则可以在严格模式下抑制无效值的错误。In this case, a warning is generated rather than an error. For 在这种情况下,将生成一个警告,而不是一个错误。对于ENUM, the value is inserted as the error member (0). ENUM,该值将作为错误成员(0)插入。For 对于SET, the value is inserted as given except that any invalid substrings are deleted. SET,除了删除任何无效的子字符串外,将按给定值插入该值。For example, 例如,'a,x,b,y' results in a value of 'a,b'.'a,x,b,y'会产生一个值'a,b'。