Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL datatype INT(11) whereas UNSIGNED INT(10)?

in MySQL if we create a field dataType of INT and does not specify any length/values then it automatically became int(11) and if we set the attribute UNSIGNED or UNSIGNED ZEROFILL then it turns into int(10)

Where does this length(1) goes?

like image 806
diEcho Avatar asked Mar 10 '11 07:03

diEcho


People also ask

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.

What is signed and unsigned in MySQL?

UNSIGNED only stores positive numbers (or zero). On the other hand, signed can store negative numbers (i.e., may have a negative sign). UNSIGNED ranges from 0 to n , while signed ranges from about -n/2 to n/2 . In this case, you have an AUTO_INCREMENT ID column, so you would not have negatives.

What is unsigned int in MySQL?

The “unsigned” in MySQL is a data type. Whenever we write an unsigned to any column that means you cannot insert negative numbers. Suppose, for a very large number you can use unsigned type. The maximum range with unsigned int is 4294967295. Note: If you insert negative value you will get a MySQL error.

What is the meaning of int 10 in MySQL?

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.


1 Answers

int value can be -2147483648 these are 11 digits so the default display size is 11

unsigned int does not allow negative numbers so by default it need only display size 10

As the documentation below shows, the number of bits required to store SIGNED INT and UNSIGNED INT is the same, the range of storable numbers is merely shifted:

Unsigned type can be used to permit only nonnegative numbers in a column or when you need a larger upper numeric range for the column. For example, if an INT column is UNSIGNED, the size of the column's range is the same but its endpoints shift from -2147483648 and 2147483647 up to 0 and 4294967295.

http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html

like image 184
Shakti Singh Avatar answered Oct 26 '22 06:10

Shakti Singh