What is the difference between int() and tinyint() in MYSQL field attributes?
In the teaching process today, I met several students who are already in the employment stage. I don’t know the difference between int() and tinyint(). I can’t help but sigh, especially here:
-
Int occupies 4 bytes, and tinyint occupies 1 byte. If you store a smaller number, use tinyint for higher performance.
-
When to use int and when to use tinyint?
When tinyint is used independently, the use range is 0-127.
The use range of tinyint unsigned is integer data from 0 to 255, and the storage size is 1 byte. The use range of int unsigned is 0 to 4294967295, and the storage size is 4 bytes. Tinyint occupies a small memory, and its scope is also small.
All things considered, I personally think that if the number is small, such as 0 and 1 for gender or age, tinyint can be used. For example: see the picture below.
However, if the number may exceed 255, int is recommended.
Disclaimer: The above texts are all personal understandings, and are limited to interactive use for students to answer questions in teaching. If there are any shortcomings, please leave your valuable suggestions.
Welcome to like and follow.