The difference and usage of tinyint(1) and tinyint(4)

1 bytes = 8 bit, the maximum data length that a byte can represent is 2 to the 8th power of 11111111. In a computer, that is

-128 to 127

1.BIT[M]

Bit field type, M represents the number of bits per value, ranging from 1 to 64, defaults to 1 if M is omitted

2.TINYINT[( M )] [UNSIGNED] [ZEROFILL] M defaults to 4

small integer. The signed range is -128 to 127. The unsigned range is 0 to 255.

3. BOOL,BOOLEAN

is a synonym for TINYINT(1). A zero value is treated as false. Non-zero values ​​are treated as true.

4.SMALLINT[( M )] [UNSIGNED] [ZEROFILL] M defaults to 6

small integer. The signed range is -32768 to 32767. The unsigned range is 0 to 65535.

5.MEDIUMINT[( M )] [UNSIGNED] [ZEROFILL] M defaults to 9

Medium sized integer. The signed range is -8388608 to 8388607. The unsigned range is 0 to 16777215.

6. INT[( M )] [UNSIGNED] [ZEROFILL] M defaults to 11

A normal-sized integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

7. BIGINT[( M )] [UNSIGNED] [ZEROFILL] M defaults to 20

large integer. The signed range is -9223372036854775808 to 9223372036854775807. The unsigned range is 0 to 18446744073709551615.

Note: The M here does not represent the specific length stored in the database. In the past, it was always misunderstood that int(3) could only store numbers of 3 lengths, and int(11) would store numbers of 11 lengths. This is dead wrong.

1 and 4 in tinyint(1) and tinyint(4) do not indicate the storage length, only the field specifying zerofill is useful,
such as tinyint(4), if the actual value is 2, if the column specifies zerofill, the query result is 0002, The left is filled with 0s.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324033497&siteId=291194637