在mysql中int(11)的列的大小是多少?
和可以存储在这些列中的最大值?
在mysql中int(11)的列的大小是多少?
和可以存储在这些列中的最大值?
当前回答
在mysql中int(11)的列的大小是多少?
(11) - int数据类型的这个属性与列的大小无关。它只是整数数据类型的显示宽度。从11.1.4.5。属性:
MySQL支持可选地指定显示的扩展 base关键字后面括号中的整数数据类型的宽度 对于类型。例如,INT(4)指定带显示的INT 四位数字的宽度。
其他回答
在mysql中int(11)的列的大小是多少?
(11) - int数据类型的这个属性与列的大小无关。它只是整数数据类型的显示宽度。从11.1.4.5。属性:
MySQL支持可选地指定显示的扩展 base关键字后面括号中的整数数据类型的宽度 对于类型。例如,INT(4)指定带显示的INT 四位数字的宽度。
根据这里,int(11)将占用4个字节的空间,即2^(31)= 2147483648 max值和-2147483648min值的32位空间。一位是符号。
我认为int(11)的最大值是4294967295
虽然这个答案不太可能出现,但我认为有必要进行以下澄清:
the (n) behind an integer data type in MySQL is specifying the display width the display width does NOT limit the length of the number returned from a query the display width DOES limit the number of zeroes filled for a zero filled column so the total number matches the display width (so long as the actual number does not exceed the display width, in which case the number is shown as is) the display width is also meant as a useful tool for developers to know what length the value should be padded to
A BIT OF DETAIL the display width is, apparently, intended to provide some metadata about how many zeros to display in a zero filled number. It does NOT actually limit the length of a number returned from a query if that number goes above the display width specified. To know what length/width is actually allowed for an integer data type in MySQL see the list & link: (types: TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT); So having said the above, you can expect the display width to have no affect on the results from a standard query, unless the columns are specified as ZEROFILL columns OR in the case the data is being pulled into an application & that application is collecting the display width to use for some other sort of padding.
主要参考资料:https://blogs.oracle.com/jsmyth/entry/what_does_the_11_mean
A good explanation for this can be found here To summarize : The number N in int(N) is often confused by the maximum size allowed for the column, as it does in the case of varchar(N). But this is not the case with Integer data types- the number N in the parentheses is not the maximum size for the column, but simply a parameter to tell MySQL what width to display the column at when the table's data is being viewed via the MySQL console (when you're using the ZEROFILL attribute). The number in brackets will tell MySQL how many zeros to pad incoming integers with. For example: If you're using ZEROFILL on a column that is set to INT(5) and the number 78 is inserted, MySQL will pad that value with zeros until the number satisfies the number in brackets. i.e. 78 will become 00078 and 127 will become 00127. To sum it up: The number in brackets is used for display purposes. In a way, the number in brackets is kind of usless unless you're using the ZEROFILL attribute. So the size for the int would remain same i.e., -2147483648 to 2147483648 for signed and 0 to 4294967295 for unsigned (~ 2.15 billions and 4.2 billions, which is one of the reasons why developers remain unaware of the story behind the Number N in parentheses, as it hardly affects the database unless it contains over 2 billions of rows), and in terms of bytes it would be 4 bytes.
关于整数类型大小/范围的更多信息,请参阅MySQL手册