当前位置:网站首页>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: 0
Insert 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 !
边栏推荐
- Drug disease association prediction based on multi-scale heterogeneous network topology information and multiple attributes
- Lecture 8: 1602 LCD (Guo Tianxiang)
- 成功解决AttributeError: Can only use .cat accessor with a ‘category‘ dtype
- LeetCode每日一题(1997. First Day Where You Have Been in All the Rooms)
- LeetCode 732. My schedule III
- 【软件测试进阶第1步】自动化测试基础知识
- 详解SQL中Groupings Sets 语句的功能和底层实现逻辑
- The registration password of day 239/300 is 8~14 alphanumeric and punctuation, and at least 2 checks are included
- Thesis abstract translation, multilingual pure human translation
- How to translate professional papers and write English abstracts better
猜你喜欢
Cobalt Strike特征修改
Changes in the number of words in English papers translated into Chinese
Luogu p2089 roast chicken
如何将flv文件转为mp4文件?一个简单的解决办法
我的创作纪念日
It is necessary to understand these characteristics in translating subtitles of film and television dramas
26岁从财务转行软件测试,4年沉淀我已经是25k的测开工程师...
[ 英语 ] 语法重塑 之 英语学习的核心框架 —— 英语兔学习笔记(1)
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
Reflex WMS medium level series 3: display shipped replaceable groups
随机推荐
Summary of leetcode's dynamic programming 4
自动化测试环境配置
Day 246/300 SSH connection prompt "remote host identification has changed!"
How to convert flv file to MP4 file? A simple solution
商标翻译有什么特点,如何翻译?
成功解决TypeError: data type ‘category‘ not understood
如何做好互联网金融的英语翻译
Chinese English comparison: you can do this Best of luck
翻译影视剧字幕,这些特点务必要了解
In English translation of papers, how to do a good translation?
Data security -- 13 -- data security lifecycle management
Reflex WMS medium level series 3: display shipped replaceable groups
[English] Verb Classification of grammatical reconstruction -- English rabbit learning notes (2)
Day 245/300 JS forEach 多层嵌套后数据无法更新到对象中
端午节快乐Wish Dragon Boat Festival is happy
How to do a good job in financial literature translation?
mysql的基础命令
LeetCode 731. My schedule II
How to translate professional papers and write English abstracts better
红蓝对抗之流量加密(Openssl加密传输、MSF流量加密、CS修改profile进行流量加密)