I'm new to web programming and doing different tutorials that I can find on the net.
I did my research and found out that in int(11), 11 is the maximum display width for integers and it's the default value if unless the integer is UNSIGNED (in this case it's 10).
When I see something like this:
id INT(11) not null AUTO_INCREMENT
I have no questions. But why do I see different things in different tutorials? For examlpe, in some, it says,
id INT(10) not null AUTO_INCREMENT
And even
id INT(4) not null AUTO_INCREMENT
What are the authors of those tuts trying to achieve? None of them seem to bother to give an explanation what 10 or 4 means.
Alright, they're obviously reducing the display width, but why? What's wrong with the default width of 11? Why would they want to change it? Or are there any other reasons I don't know of?
Thanks.
in int(11), 11 is the display width of the integer column, unlike the characters columns where the number means number of character that can be stored. int(11) – The number in the parenthesis i.e () does not determines the max and min values that can be stored in the integer field.
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.
The maximum display width is 255. Display width is unrelated to the range of values a type can store, as described in Section 11.1. 6, “Numeric Type Attributes”. For floating-point and fixed-point data types, M is the total number of digits that can be stored.
The x
in INT(x)
has nothing to do with space requirements or any other performance issues, it's really just the display width. Generally setting the display widths to a reasonable value is mostly useful with the UNSIGNED ZEROFILL
option.
//INT(4) UNSIGNED ZEROFILL 0001 0002 ... 0099 ... 0999 ... 9999 ... 10000 //INT(2) UNSIGNED ZEROFILL 01 02 ... 09 ... 99 ... 100
Without the UNSIGNED ZEROFILL
option the value will be left-padded with spaces to the appropriate display width.
//INT(4) 1 2 ... 99 ... 999 ... 9999 ... 10000 //INT(2) 1 2 ... 9 ... 99 ... 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With