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

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

Patricia Arquette
Patricia ArquetteOriginal
2024-11-02 07:45:29348browse

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:

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.

The above is the detailed content of What\'s the Difference Between TINYINT(1) and TINYINT(2) in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn