The differences between int bigint smallint and tinyint in mysql are described in detail

  • 2020-05-13 03:41:17
  • OfStack

Recently, when using mysql database, I encountered a variety of number types, mainly int,bigint,smallint and tinyint. The confusing part is the difference between int and smallint. Today, I searched the Internet carefully and found the following content. I will leave a file to make a summary:
An exact numeric data type that USES integer data.
bigint
Integer data (all Numbers) from -2^63 (-9223372036854775808) to 2^63-1 (9223372036854775807). The storage size is 8 bytes.
P.S.bigint already has a length, length in the mysql table is only used to display the number of digits
int
Integer data (all Numbers) from -2^31 (-2,147,483,648) to 2^31,1 (2,147,483,647). The storage size is 4 bytes. int is synonymous with SQL-92 as integer.
smallint
Integer data from -2^15 (-32,768) to 2^15, and 1 (32,767). The storage size is 2 bytes.
tinyint
Integer data from 0 to 255. The storage size is 1 byte.
annotation
Support bigint data types where integer values are supported. However, bigint is used for special cases where the integer value exceeds the range supported by the int data type. In SQL Server, the int data type is the primary integer data type.
In the data type priority table, bigint is located between smallmoney and int.
The function returns bigint only if the parameter expression is of type bigint data. SQL Server does not automatically promote other integer data types (tinyint, smallint, and int) to bigint.
int(M) in the integer data type, M represents the maximum display width. In int(M), the value of M has nothing to do with how much storage is consumed by int(M). int(3), int(4), int(8) all occupy 4 btyes storage space on the disk.

Related articles: