I am confused to see this tinyint(3) structure. If tinyint can store only 1 byte then what is the purpose of giving the size in brackets? Is there something special with this parameter in MySQL?
|
|
|
That's not bytes, it's display width. It's used as a hint for the maximum expected typical character width of values for the column, to applications that care to actually use the metadata -- which many don't. As explained in the documentation:
The default value for an unsigned tinyint is (3) because that's the size of "255" which the widest number (in displayed character positions) that can be stored in an an unsigned tinyint. The display width also does not change the storage requirements for the data types; so, for example, an INT(1) still takes up 4 bytes of storage. |
|||
|
|
|
It's just used when zerofill is activated, see bellow:
we have 2 fields with same size, but b has zerofill activated, lets insert some rows in this table
and now when we retrieve this row we see the difference:
on |
|||
|
|

