Home >Database >Mysql Tutorial >Tinyint(2) vs Tinyint(1) in MySQL: What\'s the Difference in Display Width?
MySql: Tinyint (2) vs tinyint(1) - Variance Explained
The concept of boolean data types being represented as tinyint (1) is well-known in MySQL. However, encountering a table defined with tinyint(2), int(4), int(6), and similar constructs can raise questions about the significance of these values.
What Do Size Designations Mean in Integer and Tinyint Fields?
The (m) within the field declaration, such as tinyint(2), denotes the column's display width. Applications like the MySQL client utilize this to format query results, as demonstrated below:
| v | a | b | c | +-----+-----+-----+-----+ | 1 | 1 | 1 | 1 | | 10 | 10 | 10 | 10 | | 100 | 100 | 100 | 100 |
Here, a, b, and c are defined as TINYINT(1), TINYINT(2), and TINYINT(3), respectively. Notice how the values are padded on the left to match the specified display width.
Impact of Display Width
It's crucial to note that the display width does not impact the accepted range of values for the data type. For instance, TINYINT(1) still accepts values within the range [-128 to 127], regardless of the display width.
The above is the detailed content of Tinyint(2) vs Tinyint(1) in MySQL: What\'s the Difference in Display Width?. For more information, please follow other related articles on the PHP Chinese website!