22 September 2011

MySQL int(11) - what does 11 mean?

Actually i want to answer 2 questions by this post. First one is what is that 11 (size) number and what is the limit of the MySQL INT field.

INT(11) - means a normal INT field, that will display as ZERO all numbers lower than 11 digits. We can set 4 there and we'll get the folowing example:

CREATE TABLE `foo` (
`bar` int(4) unsigned zerofill DEFAULT NULL
);

 SELECT * FROM foo;
+---------+
| bar     |
+---------+
|    0042 | 
|    0101 | 
| 9876543 | 
+---------+
It is not a limit for the size of the INT field (eg. from 0 to 9999). The INT size is always 4 bytes, going between -2,147,483,648 and 2,147,483,647 or if it's not signed (+/- values) going from 0 to 4,294,967,295.

No comments:

Post a Comment