I knew boolean in mysql as tinyint (1)
.
Today I see a table with defined an integer like tinyint(2)
, and also others like int(4)
, int(6)
...
What does the size means in field of type integer and tinyint ?
The (m)
indicates the column display width; applications such as the MySQL client make use of this when showing the query results.
For example:
| v | a | b | c |
+-----+-----+-----+-----+
| 1 | 1 | 1 | 1 |
| 10 | 10 | 10 | 10 |
| 100 | 100 | 100 | 100 |
Here a
, b
and c
are using TINYINT(1)
, TINYINT(2)
and TINYINT(3)
respectively. As you can see, it pads the values on the left side using the display width.
It's important to note that it does not affect the accepted range of values for that particular type, i.e. TINYINT(1)
still accepts [-128 .. 127]
.