"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > What\'s the Difference Between TINYINT(1) and TINYINT(2) in MySQL?

What\'s the Difference Between TINYINT(1) and TINYINT(2) in MySQL?

Published on 2024-11-04
Browse:520

What\'s the Difference Between TINYINT(1) and TINYINT(2) in MySQL?

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:

TableColumnDisplay Width
vTINYINT(1)1
aTINYINT(2)2
bINT(4)4
cINT(6)6

As illustrated in the table:

vabc
1111
10101010
100100100100

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.

Latest tutorial More>

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