1.7.3.4 ENUM and SET ConstraintsENUM和SET约束

ENUM and SET columns provide an efficient way to define columns that can contain only a given set of values. ENUMSET列提供了一种有效的方法来定义只能包含给定值集的列。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 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:除非禁用了严格模式(不建议使用,但请参阅第5.1.11节,“服务器SQL模式”),否则ENUMSET列的定义将对输入该列的值起约束作用。对于不满足以下条件的值,会发生错误:

Errors for invalid values can be suppressed in strict mode if you use INSERT IGNORE or UPDATE IGNORE. 如果使用INSERT IGNOREUPDATE 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'