MySql: Tinyint (2) vs tinyint(1) - what is the difference?

前端 未结 4 594
轮回少年
轮回少年 2020-11-29 15:38

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)

4条回答
  •  渐次进展
    2020-11-29 16:20

    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].

提交回复
热议问题