29

In MySQL table definitions is there a different between INT(5) and SMALLINT(5)? Or do they both represent the same size?

41

An int and a smallint have different sizes and consequently ranges. The (5) is smallint(5) or int(5) is called a "Numeric Type Attribute" and it represents the "display width" of the field,

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.)

When used in conjunction with the optional (nonstandard) attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.

This is a MySQL "extension", and zerofill is an "extension" on an extension.

For the sane method of controlling the display of a numeric type, don't ues Numeric type Attributes and instead use

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.