mysql tinyint(1) vs tinyint(2) vs tinyint(3) vs tinyint(4)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13120904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:18:46  来源:igfitidea点击:

mysql tinyint(1) vs tinyint(2) vs tinyint(3) vs tinyint(4)

mysql

提问by Tarun Gupta

Possible Duplicate:
MySql: Tinyint (2) vs tinyint(1) - Which difference?

可能的重复:
MySql: Tinyint (2) vs tinyint(1) - 哪个区别?

What is the difference between:

有什么区别:

  • TinyINT(1)
  • TinyINT(2)
  • TinyINT(3)
  • TinyINT(4)
  • TinyINT(1)
  • TinyINT(2)
  • TinyINT(3)
  • TinyINT(4)

回答by muehlbau

TinyINT(M) always has a range from -128..+127 signed or 0..255 unsigned. M is the display width.

TinyINT(M) 的范围始终为 -128..+127 有符号或 0..255 无符号。M 是显示宽度。

M indicates the maximum display width for integer types. The maximum display width is 255. Display width is unrelated to the range of values a type can contain, as described in Section 11.2, “Numeric Types”. For floating-point and fixed-point types, M is the total number of digits that can be stored.

M 表示整数类型的最大显示宽度。最大显示宽度为 255。显示宽度与类型可以包含的值范围无关,如第 11.2 节“数字类型”中所述。对于浮点和定点类型,M 是可以存储的总位数。

from http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

来自http://dev.mysql.com/doc/refman/5.5/en/numeric-type-overview.html

回答by Vyktor

According to Mysql manualall decimal numeric types supports syntax:

根据Mysql 手册,所有十进制数字类型都支持语法:

Integer Types (Exact Value)

When using DECIMALit allows you to specify precision.

使用DECIMAL它时,您可以指定 precision

With *INTtypes it's has mainly display functionwhich also specifies how many places should be added when using ZEROFILL.

对于*INT类型,它主要具有显示功能,该功能还指定使用ZEROFILL.

The byte size remains unaffected (1Bfor TINYINT).

字节大小不受影响(1BforTINYINT)。

回答by Francois

TinyINT = -128...+127

TinyINT = -128...+127

(n) is for display purposes.

(n) 用于显示目的。