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/02 Report--
This article mainly introduces what is the difference between tinyint and int in Mysql, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
Question: what is the difference between int (1) and tinyint (1)?
For a design like this, I won't write int (1) anyway.
Check out that after setting the storage type in mysql, the storage is fixed, that is, int (1) and int (4) occupy the same number of bytes in the hard disk.
We know that the int type is 4 bytes and tinyint is 1 byte. Int (1) and int (4) are the same in terms of their own length or storage mode, except that the length of the display is different, but set a parameter: if the column is defined by zerofill, the display will be filled with 0, and the specified int (4) will be displayed as 0002.
Compared with tinyint (4), int (1) definitely has a larger int.
Note that the number in parentheses after the number type does not represent the length, but the display width, which is different from the meaning of the number after varchar and char.
That is, no matter what the number after int is, 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, they occupy the same storage space.
Tinyint one byte smallint two bytes MEDIUMINT three bytes
Obviously, int (1) and tinyint (1) should choose tinyint (1) when designing the database. The less storage space, the better. Of course, it has to be enough. To store a single-digit field like this, it's better to use tinyint (1).
Summary:
1. After the type is specified, the storage is fixed length, and int (1) and int (4) are the same in length and storage mode. In mysql, the difference between int (1) and int (4) is the length of the display, but set a parameter: if the column is specified, zerofill will be filled with 0, such as 2 int (3) will be displayed as 002
2.int storage occupies 4 bytes and tinyint storage occupies 1 byte, and the storage length determines the range of numbers they represent. The range of numbers represented by int is integer data (all digits) from-2 ^ 31 (- 2147483648) to 2 ^ 31-1 (2147483647). The number represented by tinyint is in the range of 0-255.
3.tinyint (1), which is no different from tinyint (3), can be saved with 123, but if tinyint (3) zerofill, insert the value 12, it will store 012 Zerofill automatically zero to the left, which is the limit of display length.
The summary above is a bit of a mess. The following is a concise summary:
There is no difference between tinyint (1) and tinyint (3). Both bytes are occupied by one bit and the storage range is the same.
Tinyint (3) zerofill, when the inserted data is less than 3 digits, the left side automatically fills in zero, which is the limit of display length.
Int (1) and tinyint (1), where sufficient, tinyint (1) is preferred because it takes up fewer bytes and saves space.
Tinyint one byte smallint two bytes MEDIUMINT three bytes int four bytes BIGINT eight bytes.
However, the 5 here in varchar (5) limits the number of characters stored, regardless of whether they are high or low (regardless of Chinese, English, numbers.).
Thank you for reading this article carefully. I hope the article "what is the difference between tinyint and int in Mysql" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.