Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does INT(5) in mysql mean?

Tags:

database

mysql

I always thought INT(5) means a number which has a max size of 5 digits. I tried entering a huge number inside it and it somehow got cut down to 2147483647

This obviously isnt 5 digits. So what does INT(5) have a limitation of ?

like image 262
YD8877 Avatar asked Jan 17 '12 09:01

YD8877


People also ask

What does Int 4 mean in MySQL?

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.

What does int mean in MySQL?

In MySQL, INTEGER (INT) is a numeric value without a decimal. It defines whole numbers that can be stored in a field or column. In addition, MySQL supports the display_width attribute (for example, INT(1)) and the ZEROFILL attribute, which automatically adds zeros to the value depending on the display width.

What does int 10 mean in SQL?

INT(10) means you probably defined it as INT UNSIGNED . So, you can store numbers from 0 up to 4294967295 (note that the maximum value has 10 digits, so MySQL automatically added the (10) in the column definition which (10) is just a format hint and nothing more. It has no effect on how big number you can store).

What means INT 11 in MySQL?

In MySQL integer int(11) has size is 4 bytes which equals 32 bit. Signed value is : - 2^(32-1) to 0 to 2^(32-1)-1 = -2147483648 to 0 to 2147483647. Unsigned values is : 0 to 2^32-1 = 0 to 4294967295.


2 Answers

From MySQL Docs, 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.)

like image 97
ypercubeᵀᴹ Avatar answered Oct 15 '22 22:10

ypercubeᵀᴹ


INT is always four bytes wide. The 5 is the "display width".

like image 37
NPE Avatar answered Oct 15 '22 21:10

NPE