Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why INT(11) when it only stores 10 digits?

Tags:

sql

int

mysql

I know that the number inside parenthesis does not control the storage limit; but I am curious why it is popular to write INT(11) when it only stores 10 digits (unsigned 4,294,967,295). Using numbers smaller than the capacity like tinyint(1) is understandable but why higher?

like image 977
Googlebot Avatar asked Mar 15 '12 13:03

Googlebot


3 Answers

A signed integer is 11: 10 digits + 1 sign

An unsigned integer is 10.

like image 79
Brian Driscoll Avatar answered Oct 21 '22 11:10

Brian Driscoll


That's because the 11 counts the sign digit

like image 5
Schiavini Avatar answered Oct 21 '22 10:10

Schiavini


When dealing with the INT type, the "size" is the display size. An INT is 4 bytes.

The extra (10 + 1) is for the minus sign. If you make it an unsigned int, the size will default to 10 instead of 11.

There would be no reason to go beyond 11.

like image 1
Marcus Adams Avatar answered Oct 21 '22 10:10

Marcus Adams