📜  mysql size int - SQL (1)

📅  最后修改于: 2023-12-03 15:17:46.248000             🧑  作者: Mango

MySQL Size INT - SQL

Introduction

MySQL is one of the most popular open-source relational database management systems. One of the data types it provides is the INT, which is used to store integers of various sizes. The size of an INT can have different meanings depending on whether it is signed or unsigned. The size of an INT can also affect the maximum and minimum values that can be stored in it.

Signed and Unsigned INT

An INT can be either signed or unsigned. A signed INT can store both positive and negative numbers, while an unsigned INT can store only positive numbers. The size of the INT is specified when it is created, usually with a length parameter.

Here is an example of creating a table with an INT column:

CREATE TABLE myTable (
    myColumn INT(10) UNSIGNED
);

In this example, the INT column is specified as unsigned and has a length of 10. This means that it can store values between 0 and 4,294,967,295.

If the INT column were specified as signed, it could store values between -2,147,483,648 and 2,147,483,647.

Size and Range of INT

The size of an INT determines the range of values that can be stored in it. Here are the different sizes of INT, along with their ranges:

| Size | Range (Signed) | Range (Unsigned) | |------|----------------|------------------| | 1 | -128 to 127 | 0 to 255 | | 2 | -32,768 to 32,767 | 0 to 65,535 | | 3 | -8,388,608 to 8,388,607 | 0 to 16,777,215 | | 4 | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |

As can be seen from the table, the larger the size of the INT, the larger the range of values that can be stored in it. However, it's important to note that larger sizes also mean more storage space used.

Conclusion

In conclusion, the size of an INT in MySQL determines the range of values that can be stored in it. The size can also affect the amount of storage space used. When choosing the size of an INT, it's important to consider the range of values that will be stored in it and the amount of storage space available.