当前位置:网站首页>Difference between tinyint and int
Difference between tinyint and int
2022-06-12 15:44:00 【AlbenXie】
problem :int(1) and tinyint(1) What's the difference ?
A design like this , Anyway, I can't write int(1) Of .
Look up the ,mysql After the storage type is set in , Storage is fixed length , in other words ,int(1) and int(4) The number of bytes in the hard disk is the same .
We know ,int Type account 4 Bytes ,tinyint Occupy 1 Bytes .int(1) and int(4) The length and storage method are the same , The difference is the length of the display , But set a parameter : If the column has zerofill Will use 0 Fill display ,int(4) When specified, it will be displayed as 0002.
int(1) and tinyint(4) comparison , sure int Big .
Notice the number in parentheses after the number type , Does not represent length , Indicates the display width , With this varchar、char The following numbers have different meanings .
That is to say, regardless of int What's the number after that , Its storage range is always -2^31 To 2^31 - 1.
To sum up, no matter how many numbers are in parentheses for integer data types , The storage space occupied is the same
tinyint A byte smallint Two bytes MEDIUMINT Three bytes
Obvious ,int(1) and tinyint(1) , When designing a database, you should choose tinyint(1). The less storage space it takes up, the better , Of course, it needs to be enough . Store one like this Single digit field , Or use it tinyint(1) Good. .
summary :
1. After specifying the type , The storage is fixed in length ,int(1) and int(4) The length and storage method are the same .mysql in ,int(1) and int(4) The difference is the length of the display , But set a parameter : If the column has zerofill Will use 0 Fill display , Such as 2 int(3) When specified, it will be displayed as 002
2.int Storage 4 Bytes , tinyint Storage 1 Bytes , The storage length determines the range of numbers they represent .int The range of numbers represented is : from -2^31 (-2,147,483,648) To 2^31 – 1 (2,147,483,647) The integer data of ( All figures ).tinyint The range of representation is 0-255 Number between .
3.tinyint(1), and tinyint(3) No difference , save 123 Can be saved , And if the tinyint(3) zerofill Words , Insert value 12, Will store 012,zerofill Auto zero left , That's what limits the display length .
The above summary is a little messy . The following is a brief summary :
- tinyint(1) and tinyint(3) No difference , All occupied bytes are one bit , The storage range is the same
- tinyint(3) zerofill , When the inserted data is less than 3 When a , Automatic zero filling on the left , That's what limits the display length
- int(1) and tinyint(1) , When it's enough , Preference tinyint(1), Because it takes less bytes 、 Save a space .
- tinyint A byte smallint Two bytes MEDIUMINT Three bytes int 4 Bytes BIGINT 8 Bytes .
however ,varchar(5) there 5 The limit is the number of stored characters , Characters don't distinguish between high and low ( Regardless of chinese 、 english 、 Numbers ...).
边栏推荐
- Codeworks round 797 (Div. 3, cf1690)
- C语言 分割bin文件程序
- How to write year-end summary
- 安装rhel 7/8 (红帽)虚拟机(转载)
- Find the number of cells (connectivity map, wide search, deep search)
- vim的安装以及常用命令
- Idea大全(转载)
- Servlet连接数据库实现用户登录功能
- UDP summary (tcp/ip details volume 1/2)
- Pta: self test -2 prime pair conjecture (20 points)
猜你喜欢

Scala download and idea installation of scala plug-ins (nanny level tutorial is super detailed)

UDP summary (tcp/ip details volume 1/2)

Five models of software testing

Explanation of socket principle (where, what and how to use it)

FPGA (III) trigger and latch

Deepin20.6 RTX3080 安裝顯卡驅動510.60.02、CUDA11.6、PyTorch1.11

Acwing summer daily question (sexy prime number on June 10)

Two ways of array simulating queue

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

Jupyter notebook new environment shortcut
随机推荐
Daily leetcode - 3 Longest substring without duplicate characters
Pta: self test -3 array element cyclic right shift problem (20 points)
RARP总结(TCP/IP详解卷1/2)
【无标题】
Use and understanding of generics
Rust tip - running the tensorrt model through FFI programming
Jupyter notebook new environment shortcut
mysql Blob和Text类型
MySQL development considerations (Alibaba development manual)
Conversion between sparse array and array and file reading and writing
Microservice fault tolerance
任务 输出密雪冰城主题曲 0612
Particle filter learning record
Explanation of socket principle (where, what and how to use it)
ARM 64指令小记
UE4 common type conversion
Servlet connects to database to realize user login function
[jvm learning] types of GC and allocation process of objects on JVM heap
How to set public IP access on the H3C gr5200 router
TS 22.011