11.1.1 Numeric Data Type Syntax数字数据类型语法

For integer data types, M indicates the maximum display width. 对于整数数据类型,M表示最大显示宽度。The maximum display width is 255. 最大显示宽度为255。Display width is unrelated to the range of values a type can store, as described in Section 11.1.6, “Numeric Type Attributes”.显示宽度与类型可以存储的值范围无关,如第11.1.6节,“数字类型属性”所述。

For floating-point and fixed-point data types, M is the total number of digits that can be stored.对于浮点和定点数据类型,M是可以存储的总位数。

As of MySQL 8.0.17, the display width attribute is deprecated for integer data types; you should expect support for it to be removed in a future version of MySQL.从MySQL8.0.17开始,整数数据类型不再使用display width属性;您应该期望在MySQL的未来版本中删除对它的支持。

If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.如果为数字列指定ZEROFILL,MySQL会自动向该列添加UNSIGNED属性。

As of MySQL 8.0.17, the ZEROFILL attribute is deprecated for numeric data types; you should expect support for it to be removed in a future version of MySQL. 从MySQL8.0.17开始,数字数据类型不推荐使用ZEROFILL属性;您应该期望在MySQL的未来版本中删除对它的支持。Consider using an alternative means of producing the effect of this attribute. 考虑使用另一种方法来产生此属性的效果。For example, applications could use the LPAD() function to zero-pad numbers up to the desired width, or they could store the formatted numbers in CHAR columns.例如,应用程序可以使用LPAD()函数将填充数字归零到所需的宽度,也可以将格式化的数字存储在CHAR列中。

Numeric data types that permit the UNSIGNED attribute also permit SIGNED. 允许UNSIGNED属性的数字数据类型也允许SIGNED属性。However, these data types are signed by default, so the SIGNED attribute has no effect.但是,这些数据类型在默认情况下是有符号的,因此SIGNED属性无效。

As of MySQL 8.0.17, the UNSIGNED attribute is deprecated for columns of type FLOAT, DOUBLE, and DECIMAL (and any synonyms); you should expect support for it to be removed in a future version of MySQL. 从MySQL 8.0.17开始,对于FLOATDOUBLEDECIMAL(以及任何同义词)类型的列,UNSIGNED属性就不再使用了;您应该期望在MySQL的未来版本中删除对它的支持。Consider using a simple CHECK constraint instead for such columns.考虑对此类列使用简单的CHECK约束。

SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE.SERIALBIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE的别名。

SERIAL DEFAULT VALUE in the definition of an integer column is an alias for NOT NULL AUTO_INCREMENT UNIQUE.SERIAL DEFAULT VALUE在整型数列的定义中是NOT NULL AUTO_INCREMENT UNIQUE的别名。

Warning警告

When you use subtraction between integer values where one is of type UNSIGNED, the result is unsigned unless the NO_UNSIGNED_SUBTRACTION SQL mode is enabled. 如果在整型值之间使用减法,其中一个值的类型为UNSIGNED,则结果为无符号的,除非启用了NO_UNSIGNED_SUBTRACTION SQL模式。See Section 12.11, “Cast Functions and Operators”.请参见第12.11节,“Cast函数和运算符”