principlesqlMajor
INT(5) vs SMALLINT(5): numbers in parenthesis after the numeric type
Viewed 0 times
aftersmallintthenumericnumberstypeparenthesisint
Problem
In MySQL table definitions is there a different between
INT(5) and SMALLINT(5)? Or do they both represent the same size?Solution
An
The
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,
When used in conjunction with the optional (nonstandard) attribute
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
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
FORMAT
LPAD
RPAD
Context
StackExchange Database Administrators Q#369, answer score: 43
Revisions (0)
No revisions yet.