Data type confusion: what is an int (11 )?, Confusionint
Http://everythingmysql.ning.com/profiles/blogs/data-type-confusion-what-is-an
Over and over I see MERs that don't understand whatint(11)
Really means. Their confusion is understandable. Unknown know what definingchar(10)
Means (a fixed-sized character string that allows up to 10 characters). However, ints are different.
First of all, there are 5 types of integer. They are all fixed size.
Type |
# Of bytes |
Tinyint |
1 |
Smallint |
2 |
Mediumint |
3 |
Int |
4 |
Bigint |
8 |
As you can see from the chart,int
IsAlways4 bytes. That can store signed numbers from-2 billion to + 2 billion (and unsigned numbers 0 to 4B). So, what does it mean if you declareint(5)
? It does not restrict the number of digits to 5... It may be actually do nothing! The (5) part is a display width. it's only used if you use UNSIGNED and ZEROFILL with an integer type. then the display of those numbers will be zero-padded on the left to 5 digits if they contain less than 5 digits. example:
CREATE TABLE `foo` (
`bar` int(5) unsigned zerofill DEFAULT NULL
)
SELECT * FROM foo;+---------+
| bar |
+---------+
| 00042 |
| 00101 |
| 9876543 |
+---------+