Recently, mysql Databases have encountered multiple numeric types, including int, bigint, smallint, and tinyint. The difference between int and smallint is confusing. Today, I searched for the following content on the Internet, and made a summary:
Use the exact numeric data type of integer data.
Bigint
Integer Data from-2 ^ 63 (-9223372036854775808) to 2 ^ 63-1 (9223372036854775807) (All numbers ). The storage size is 8 bytes.
P.S. bigint has a length. The length in the mysql table is only used to display the digits.
Int
Integer Data from-2 ^ 31 (-2,147,483,648) to 2 ^ 31-1 (2,147,483,647) (All numbers ). The storage size is 4 bytes. The SQL-92 synonym for the int Is integer.
Smallint
Integer Data from-2 ^ 15 (-32,768) to 2 ^ 15-1 (32,767. The storage size is 2 bytes.
Tinyint
Integer Data from 0 to 255. The storage size is 1 byte.
Note
The bigint data type is supported where integer values are supported. However, bigint is used in some special cases. When the integer value exceeds the range supported by the int data type, bigint can be used. In SQL Server, the int data type is the main integer data type.
In the data type precedence table, bigint is located between smallmoney and int.
The function returns bigint only when the parameter expression is of the bigint data type. SQL Server does not automatically upgrade other integer data types (tinyint, smallint, and int) to bigint.
Int (M) in integer data type, M indicates the maximum display width. In int (M), the value of M has nothing to do with the storage space occupied by int (M. There is no relationship with the number of digits. int (3), int (4), and int (8) occupy the storage space of 4 btyes on the disk.