TINYINT(1) and TINYINT(2) in MySQL: Uncovering the Display Width
MySQL offers two similar data types for representing tiny integers: TINYINT(1) and TINYINT(2). While both can store values within a specified range, they differ in their display width.
The (m) in TINYINT(m) denotes the display width, which is used by applications like the MySQL client when presenting query results. The display width determines the number of characters used to display the values in that column.
For example, consider the following table with columns of varying display widths:
Table | Column | Display Width |
---|---|---|
v | TINYINT(1) | 1 |
a | TINYINT(2) | 2 |
b | INT(4) | 4 |
c | INT(6) | 6 |
As illustrated in the table:
v | a | b | c |
---|---|---|---|
1 | 1 | 1 | 1 |
10 | 10 | 10 | 10 |
100 | 100 | 100 | 100 |
It's evident that TINYINT(1), TINYINT(2), and TINYINT(3) display values with padding on the left side to meet their respective display widths.
It's crucial to emphasize that the display width does not affect the range of accepted values for a given data type. TINYINT(1) still allows values within [-128 .. 127], regardless of its display width.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3