MySQL枚举与集 [英] MySQL enum vs. set

查看:158
本文介绍了MySQL枚举与集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于MySQL数据类型枚举和设置使用一个与另一个的区别和优点和缺点?



示例数据类型: / p>


  • 枚举('A','B','C')

  • ','B','C')



我知道的唯一区别是ENUM只允许一个值选择与SET允许选择多个值。

解决方案

作为 MySQL文档说明:


ENUM或SET列的定义确实充当对输入到列中的值
的约束。对于不满足以下条件的值,出现错误:



ENUM值必须是列定义中列出的值之一,或
其内部数值等效。该值不能是错误
的值(即,0或空字符串)。对于定义为
ENUM('a','b','c')的列,诸如'','d'或'ax'之类的值是非法的并且
被拒绝。 p>

SET值必须是空字符串或仅由列定义中列出的
值组成的值,以逗号分隔。对于定义为SET('a','b','c')的
列,诸如'd'或'a,b,c,d'
等值是非法的,



For MySQL Data type of "enum" and "set" what are the differences and advantages and disadvantages of using one versus the other?

Example data type:

  • enum('A', 'B', 'C')
  • set('A', 'B', 'C')

The only difference that I am aware of is that ENUM only allows one value to be selected versus SET allows multiple values to be selected.

解决方案

As the MySQL documentation states:

Definition of a ENUM or SET column does act as a constraint on values entered into the column. An error occurs for values that do not satisfy these conditions:

An ENUM value must be one of those listed in the column definition, or the internal numeric equivalent thereof. The value cannot be the error value (that is, 0 or the empty string). For a column defined as ENUM('a','b','c'), values such as '', 'd', or 'ax' are illegal and are rejected.

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 illegal and are rejected.

这篇关于MySQL枚举与集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆