当前位置:网站首页>tinyint和int区别
tinyint和int区别
2022-06-12 15:28:00 【AlbenXie】
问题:int(1) 和 tinyint(1) 有什么区别呢?
像这样的设计,反正我是不会写int(1)的。
查了下,mysql中设置了储存类型后,储存是定长的,也就是说,int(1) 和 int(4) 在硬盘中所占的字节数都是一样的。
我们知道,int类型占4个字节,tinyint占1个字节。int(1) 和 int(4) 从本身长度还是存储方式上都是一样的,区别就是显示的长度不同,但是要设置一个参数:如果列制定了zerofill 就会用0填充显示,int(4)指定后就会显示为0002。
int(1)和tinyint(4) 相比,肯定int 大。
注意数字类型后面括号中的数字,不表示长度,表示的是显示宽度,这点与 varchar、char 后面的数字含义是不同的。
也就是说不管 int 后面的数字是多少,它存储的范围始终是 -2^31 到 2^31 - 1。
综上整型的数据类型括号内的数字不管是多少,所占的存储空间都是一样
tinyint一个字节 smallint 两个字节 MEDIUMINT三个字节
显而易见,int(1) 和 tinyint(1) ,在设计数据库的时候应该选择tinyint(1)。所占的储存空间越少越好,当然要够用才行。像这样储存一个 个位数的字段,还是用tinyint(1)的好。
总结:
1.规定类型之后,存储是定长的,int(1)和int(4)从本身长度还是存储方式上都是一样的。mysql里,int(1)和int(4)的区别就是显示的长度,但是要设置一个参数:如果列制定了zerofill 就会用0填充显示,如2 int(3)指定后就会显示为002
2.int 存储占4个字节, tinyint 存储占1个字节,存储长度决定了他们表示的数字范围不同。int表示的数字范围是:从 -2^31 (-2,147,483,648) 到 2^31 – 1 (2,147,483,647) 的整型数据(所有数字)。tinyint 表示的范围是0-255之间的数字。
3.tinyint(1),和tinyint(3)没什么区别,存123都能存的下,而如果tinyint(3) zerofill 的话,插入值 12,会存储012,zerofill自动左边补零,这才是限制显示长度。
上面总结的有点乱。下面精简总结:
- tinyint(1) 和 tinyint(3) 没什么区别,占用字节都是一位,存储范围都是一样的
- tinyint(3) zerofill ,当插入的数据少于3位的时候,左边自动补零,这才是限制显示长度
- int(1) 和 tinyint(1) ,够用的情况下,优先选择tinyint(1),因为占字节少、节省空间。
- tinyint一个字节 smallint 两个字节 MEDIUMINT三个字节 int 4个字节 BIGINT 8个字节。
但是,varchar(5) 这里的5 限制的是储存字符的个数,字符不分贵贱(不分 中文、英文、数字...)。
边栏推荐
- Application of postman-rest client plug-in
- 2021-06-20
- PTA:自测-1 打印沙漏 (20分)
- The difference and brief description of "file name" and < file name > import header file used in # include
- Rust tip - running the tensorrt model through FFI programming
- 广播和多播(TCP/IP详解卷1/2)
- Is it safe to open an account for flush mobile stock trading
- ngork实现内网穿透--免费
- org. xml. sax. SAXParseException; lineNumber: 63; columnNumber: 10; The definition of "mapper" in the related type must be matched with "(CAC
- 3D reconstruction system | L3 dual view motion recovery structure (SFM binocular SFM)
猜你喜欢

Deepin20.6 rtx3080 installing graphics card drivers 510.60.02, cuda11.6, pytorch1.11

Use of multithreading

Tcp/ip three handshakes and four waves (interview questions)

Interface.

Idea Encyclopedia (Reprinted)

Pta: self test -3 array element cyclic right shift problem (20 points)

任务 输出密雪冰城主题曲 0612

Multi thread knowledge induction
![[practical case of light source] UV-LED curing innovation makes the production line more smooth](/img/6f/04f52a37782c54b1050f908f46eadf.png)
[practical case of light source] UV-LED curing innovation makes the production line more smooth

C language partition bin file program
随机推荐
CUDA out of memory or brokenpipeerror: [errno 32] broken pipe or oserror: [winerror 1455] solution to the problem that the page file is too small
Use of packet capturing tool Fiddler: simulating speed limit test process in weak network environment
RARP总结(TCP/IP详解卷1/2)
ROS beginners write the server that the little turtle rotates a certain angle at a certain speed
FIRSTVT和LASTVT白话版
Instructions de soumission des tâches télécharger les tâches sur le disque réseau
Loadbalancer load balancer
Deepin20.6 rtx3080 installer le lecteur de carte graphique 510.60.02, cuda 11.6, pytorch1.11
vim的安装以及常用命令
MySQL development considerations (Alibaba development manual)
Use of multithreading
Two implementation methods of generic interface
虚拟机中用户和root忘记密码解决办法
Points chocolate (two points answer) Blue Bridge Cup provincial competition
Understanding of dart typedef
PTA:自测-1 打印沙漏 (20分)
Pta: self test -2 prime pair conjecture (20 points)
How to write year-end summary
Self induction of exception handling
Deepin20.6 rtx3080 installing graphics card drivers 510.60.02, cuda11.6, pytorch1.11