MySQL: Display Width Of Integer Data Type

Sometimes junior database developers are being confused by field types like INT(2). Does it mean 2 bytes or 2 digits only?

However it is just optional field width which in conjunction with the optional extension attribute ZEROFILL allows to replace the default padding of spaces with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004.

Therefore the display width does not constrain the range of values that can be stored in the column, nor the number of digits that are displayed for values having a width exceeding that specified for the column. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range allowed by three characters are displayed using more than three characters.

But according to MySQL reference manual there is a possibility of problems when MySQL generates temporary tables for some complicated joins and larger values than the display width are stored in an integer column, because in these cases MySQL assumes that the data fits into the original column width.

No Comment

No comments yet

Leave a reply