In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what is the difference between int (10) and int (11) in MySQL". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "what's the difference between int (10) and int (11) in MySQL?"
Integer data types in mysql:
Range of values for different types:
Default v display widths for different data types:
The width of the display has nothing to do with the minus sign, it only works if the ZEROFILL property is set manually. Once the ZEROFILL property is manually set, MySQL automatically sets the UNSIGNED property (that is, ZEROFILL cannot store negative numbers).
So what does the value range have to do with the display width? An experiment is done with tinyint.
First, create a table as follows:
Mysql > desc test_integer +-+ | Field | Type | Null | Key | Default | Extra | +- -+ | id | int (11) | NO | PRI | NULL | auto_increment | | test_id_1 | tinyint (1) | NO | | NULL | | test_id_2 | tinyint (4) | NO | | NULL | | +- -+-+ 3 rows in set (0.00 sec)
I created fields of signed tinyint type test_id_1 display width 1 and test_id_2 display width 4, respectively, and then inserted the data, along with the values of-128,1, and 127, to see what would happen.
Mysql > insert into test_integer (test_id_1,test_id_2) values (- 128 Warnings 128), (1 rows affected 1), (127127); Query OK, 3 Duplicates (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0
The ok prompt was inserted successfully. Let's check it.
Mysql > select * from test_integer +-+ | id | test_id_1 | test_id_2 | +-+ | 1 | 128 |-128 | | 2 | 1 | 1 | 3 | 127,127 | + -+-+ 3 rows in set (0.00 sec)
The result of the query is the same, and the conclusion is drawn from the above experiments:
The range of values that display the width integer type is irrelevant. The display width only indicates the maximum number of digits that can be displayed in mysql. If the number of digits is less than the specified width, the left side is filled with the number 0.
If a value greater than the display width is inserted, the value can still be inserted and displayed as long as the value does not exceed the range of integers of that type.
By the same token, there is no difference between int (10) and int (11), except that the display width is different. There is really no difference in storage, and the setting length is only reflected when the auto-populate ZEROFILL is set, for example, 00001 is displayed if the id=1 length is int (5).
Mysql can specify a width for an integer type, such as INT (11), which is meaningless for most applications: it does not limit the legal range of values, but specifies some of Mysql's interactive tools, such as the Mysql command line client, to display the number of characters. INT (1) and INT (8) are the same for storage and operations.
Yes, it's just useful to display the supplement 0 when setting the auto-fill.
Thank you for your reading, the above is the content of "what is the difference between int (10) and int (11) in MySQL". After the study of this article, I believe you have a deeper understanding of the difference between int (10) and int (11) in MySQL. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.