What Does Size Mean in Numberic Datatype of MySQL

What does 3 in TINYINT(3) or 11 in INT(11) mean?

It does mean neither bit or byte size of the datatype. The datatype itself has already specified the size of the storage. It is for display purpose. Following paragraphs come from MySQL Manual, http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html:

"Another extension is supported by MySQL for optionally specifying the display width of integer data types in parentheses following the base keyword for the type (for example, INT(4)). 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 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.

When used in conjunction with the optional extension attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(5) ZEROFILL, a value of 4 is retrieved as 00004. Note that if you store larger values than the display width in an integer column, you may experience problems when MySQL generates temporary tables for some complicated joins, because in these cases MySQL assumes that the data fits into the original column width. "

To check the size for each of these datatype, please go to same URL: http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html.

Reference:

http://dev.mysql.com/doc/refman/4.1/en/numeric-types.html
http://alexander.kirk.at/2007/08/24/what-does-size-in-intsize-of-mysql-mean/

No comments:

Post a Comment

Labels