Generally people miss concept about what int(11) mean in MySQL is that the column can store maximum of 11 integer value or digits in length. But this is not true.
int(11) means in MySQL is the display width of the integer column.
To completely understand the meaning of int(11)
in MySQL and display the width of an integer column we use an example where we create a table with integer fields and values.
The example shows how the int(ANY_NUMBER)
affects the value of that column.
What is the display width in MySQL?
1 2 3 4 5 6 7 8 9 |
CREATE TABLE zerofill_tests( id INT AUTO_INCREMENT PRIMARY KEY, v1 INT(2) ZEROFILL, v2 INT(3) ZEROFILL, v3 INT(5) ZEROFILL ); INSERT INTO zerofill_tests(v1,v2,v3) VALUES(1,6,9); |
Output:
Code Explanations:
- On the above SQL query first, we create a table with 4 fields. One is auto-increment and the others are integer fields with its display width.
- The V1 column has display width 2 including MySQL zero fill. You can see the value is 01, MySQL can auto-replace the display width 2 with one zero value.
MySQL int
can be signed and unsigned, I show you the table which shows the required storage and range of other integer values.
Type | Storage | Minimum Value | Maximum Value |
---|---|---|---|
(Bytes) | (Signed/Unsigned) | (Signed/Unsigned) | |
TINYINT | 1 | -128 | 127 |
0 | 255 | ||
SMALLINT | 2 | -32768 | 32767 |
0 | 65535 | ||
MEDIUMINT | 3 | -8388608 | 8388607 |
0 | 16777215 | ||
INT | 4 | -2147483648 | 2147483647 |
0 | 4294967295 | ||
BIGINT | 8 | -9223372036854775808 | 9223372036854775807 |
0 | 18446744073709551615 |
Source: Integer Types (Exact Value) – INTEGER, INT, SMALLINT, TINYINT, MEDIUMINT, BIGINT
Conclusion
Here we discuss what does int(11) means in MySQL completely with the help of an example. Than we check the other integer value’s storage and range with the help of a table.
I hope you all understand about the MySQL int(11).
Also Check:
- Get PHP Date Time Difference in Days, Hours, Minutes, and Seconds
- Remove Duplicates From an Array in JavaScript Without Using For Loop
- How to Set PHP Variable in JavaScript With Example
- PHP Timestamp to Date Readable Format With Example
Happy Coding..!
One Reply to “What Does int(11) mean in MySQL With Example”