MySQL int definition explanation
For years I have been under the assumption when I create a new column of type bigint(12) for a MySQL table that the field is limited to integers with up to 12 digits开发者_如何学Go. However, I recently noticed that values up to 16 digits are able to be written into and selected out of a bigint(12) defined column without any warnings or issues.
Can someone please help me understand why this is the case and what that column definition actually means? Thanks in advance!
bigint(12) is not truncated at all. The 12 is used for display purposes.
Have a look at Numeric Types
Numeric Type Attributes
MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)
The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly.
read Numeric Type Attributes
section from MySql documentation INT(4) specifies an INT with a display width of four digits
精彩评论