Home > Database > Mysql Tutorial > body text

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

Patricia Arquette
Release: 2024-11-02 07:45:29
Original
363 people have browsed it

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!