当前位置:网站首页>What is the difference between int (1) and int (10)? Senior developers can't tell!
What is the difference between int (1) and int (10)? Senior developers can't tell!
2022-07-06 06:46:00 【Java notes shrimp】
Click on the official account , utilize Fragment time to learn
confused
I have a problem recently , If you have a watch, you need to add user_id Field ,user_id Fields can be very large , So I mentioned mysql The repair order alter table xxx ADD user_id int(1). The leader saw my sql The repair order , So he said : this int(1) I'm afraid it's not enough , Next is an explanation .
In fact, this is not the first time I have encountered such a problem , Many of them have jobs 5 An old driver of more than years . Including I often see that my colleagues have been using int(10), It feels like it's working int(1), The upper limit of the field is limited , This is certainly not the case .
Data speak
We know that mysql in int Occupy 4 Bytes , So for unsigned int, The maximum is 2^32-1 = 4294967295, nearly 40 Billion , Did you use it int(1), Can't you reach this maximum ?
CREATE TABLE `user` (
`id` int(1) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;id The field is unsigned int(1), Let me insert a maximum to see .
mysql> INSERT INTO `user` (`id`) VALUES (4294967295);
Query OK, 1 row affected (0.00 sec) You can see the success , explain int Back number , No effect int Size supported by itself ,int(1)、int(2)...int(10) No difference .
Zero fill
commonly int Back number , coordination zerofill It works when used together . Let's take an example :
CREATE TABLE `user` (
`id` int(4) unsigned zerofill NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4; Be careful int(4) There's a... In the back zerofill, Let's insert 4 Data .
mysql> INSERT INTO `user` (`id`) VALUES (1),(10),(100),(1000);
Query OK, 4 rows affected (0.00 sec)
Records: 4 Duplicates: 0 Warnings: 0Insert separately 1、10、100、1000 4 Data , Then let's check :
mysql> select * from user;
+------+
| id |
+------+
| 0001 |
| 0010 |
| 0100 |
| 1000 |
+------+
4 rows in set (0.00 sec)Through the data, we can find int(4) + zerofill Realized the deficiency 4 Place complement 0 The phenomenon of , only int(4) It's no use .
And for 0001 such , The underlying storage is still 1, Just in the show will make up 0.
summary
int The following number cannot represent the length of the field ,int(num) General plus zerofill, It works .zerofill The function of can generally be used in some numbers related to numbers , For example, the student's number 001 002 ... 999 such , If mysql There is no function of zero padding , But when you have to format and output numbers of equal length , Then you have to deal with it yourself .

source :juejin.cn/post/6992574502282477605
recommend :
Main stream Java Advanced technology ( Learning material sharing )

PS: Because the official account platform changed the push rules. , If you don't want to miss the content , Remember to click after reading “ Looking at ”, Add one “ Star standard ”, In this way, each new article push will appear in your subscription list for the first time . spot “ Looking at ” Support us !
边栏推荐
- UniPro甘特图“初体验”:关注细节背后的多场景探索
- Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board
- [Yu Yue education] flower cultivation reference materials of Weifang Vocational College
- LeetCode 739. Daily temperature
- 删除外部表源数据
- Attributeerror successfully resolved: can only use cat accessor with a ‘category‘ dtype
- How do programmers remember code and programming language?
- CS-证书指纹修改
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 生物医学英文合同翻译,关于词汇翻译的特点
猜你喜欢

同事上了个厕所,我帮产品妹子轻松完成BI数据产品顺便得到奶茶奖励

Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks

Engineering organisms containing artificial metalloenzymes perform unnatural biosynthesis

In English translation of papers, how to do a good translation?

CS通过(CDN+证书)powershell上线详细版

My seven years with NLP

Tms320c665x + Xilinx artix7 DSP + FPGA high speed core board

Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes

Esp32 esp-idf watchdog twdt

Basic commands of MySQL
随机推荐
Day 248/300 关于毕业生如何找工作的思考
机器人类专业不同层次院校课程差异性简述-ROS1/ROS2-
Bitcoinwin (BCW): 借贷平台Celsius隐瞒亏损3.5万枚ETH 或资不抵债
Use shortcut LNK online CS
Facebook AI & Oxford proposed a video transformer with "track attention" to perform SOTA in video action recognition tasks
Day 246/300 ssh连接提示“REMOTE HOST IDENTIFICATION HAS CHANGED! ”
电子书-CHM-上线CS
雲上有AI,讓地球科學研究更省力
ECS accessKey key disclosure and utilization
Phishing & filename inversion & Office remote template
Py06 dictionary mapping dictionary nested key does not exist test key sorting
Leetcode daily question (971. flip binary tree to match preorder traversal)
pymongo获取一列数据
LeetCode每日一题(971. Flip Binary Tree To Match Preorder Traversal)
英语论文翻译成中文字数变化
[brush questions] how can we correctly meet the interview?
Leetcode - 152 product maximum subarray
[English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)
云上有AI,让地球科学研究更省力
How effective is the Chinese-English translation of international economic and trade contracts