MySQL: display column width of integer type

Display column width of integer type

1 Overview

Hello everyone, I am Ouyang Fangchao.
Regarding the value in parentheses when defining an integer, let me add.

2. Display width

Define an integer type, such as int(10), the value in the brackets is called the display width (display width), it does not define the value of the integer type, it is only valid when using zerofill to modify the corresponding integer type , and the integer type at this time should be an unsigned integer type, that is, only non-negative numbers can be stored,

drop table if exists foo;
create table foo
(
bar smallint(4) unsigned zerofill not null default 0
) engine = innodb;

Fill in the data to see the effect,

mysql> insert into foo (bar) values (3);

Inquire:

mysql> select * from foo;
+------+
| bar  |
+------+
| 0003 |
+------+
1 row in set (0.00 sec)

It can be seen that the actual value 3 has only one digit, and the display width is defined as 4, so the first three digits are supplemented with 0.

Although the problem is small, it must be paid attention to.

3. Summary

The number in the parentheses of the MySQL integer type indicates the display width.
I'm Ouyang Fangchao, and I'm interested in doing things well. If you like my article, please like, forward, comment and pay attention. See you next time.
Attached is a picture of working overtime at night and having a meeting. The meeting ended after eleven o'clock in the evening.
insert image description here

Guess you like

Origin blog.csdn.net/u012288582/article/details/131481729