The difference between int() and tinyint() of MYSQL field attributes

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:

  1. Int occupies 4 bytes, and tinyint occupies 1 byte. If you store a smaller number, use tinyint for higher performance.

  2. 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.
    Insert picture description here
    However, if the number may exceed 255, int is recommended.
    Insert picture description here
    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.

Guess you like

Origin blog.csdn.net/qq_41475067/article/details/112022762