Your solution to the confusion is
In Mysql, int (6) does not mean that they can store up to 6 digits. no more than 999999.
However, CHAR (6) This means a character column with a maximum length of 6 characters, for example, these words:
houses
If I tried to keep the word “special” in this column, MySQL would slice the value “specia” because the original word has 7 characters.
In any case, whole columns have a given range of valid values. The number in parentheses indicates only the width of the display.
This is probably still confusing, so let me explain in more detail ...
The width of the display is a number from 1 to 255. You can set the width of the screen if you want all your integer values to "display" in the same way:
TINYINT [(M)] [UNSIGNED] [ZEROFILL]
M indicates the maximum display width for integer types. The maximum width of the screen is 255. The width of the display is not related to the range of values that the type may contain. For floating point and fixed point types, M is the total number of digits that can be stored.
If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.
So the answer to your question
create table foo ( col2 tinyint(2) unsigned zerofill, col4 tinyint(4) unsigned zerofill, col5notzerofill tinyint(5) )engine=innodb; insert into foo values (1,2,3),(11,12,14),(123,123,156),(1234,1234,12756); select * from foo; OUTPUT :- +
* So, we understand that in Mysql the display width only works with zerofill.
* If you use, do not use zerofill, it is not effective.
And if you use zerofill, then mysql will check the display of widht, and if you do not assign, then mysql will automatically assign the display width to this column. *