Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Ask a master: How does SQL get the maximum value of a data type?
Ask a master: How does SQL get the maximum value of a data type?
This requires some basic knowledge of computer principles.

Take the integer type (int, smallin.tinyint.bigint) as an example. How many numbers are written in parentheses is the storage space of the maximum number of digits+1. In addition, it depends on whether negative values are supported.

For example, Tinyint(4) uz is an 8-bit integer value range from 0 to 255.

The maximum number of three digits is 999+1, so 4 represents three digits, and the digits of three digits are byte, that is, the 8-bit (binary) integer uz is unsigned. Negative values are not supported. So it's 0-255

Tinyint(4) is a signed 8-bit integer with the range of-127~ 127.

Smallint(6) uz Maximum value 65535 Minimum value 0 is 16-bit integer.

The maximum value of int( 1 1) is 2 147483647, and the minimum value is -2 147483647 10 (decimal 10), so it is written in brackets.

The maximum value of int( 1 1) uz is 4294967295, and the minimum value is 0.

And so on, so bigint(20) corresponds to a long integer (64 bits long), and tinyint (1) corresponds to 1 bit, that is, bool is represented by 0 or 1.

Enum enumeration can actually be an enumeration form of 8-bit, 16-bit and 32-bit integers. The strange thing about mysql's American TV series is whether it starts with 1

Set can actually be a set type of 8 bits 16 bits, 32 bits, 64 bits and so on. 64 elements are 64 bits.

As for the fact that the string is a char array, if it is utf8 encoded, the actual digits are not necessarily equal. If utf 16 supports Notnull strings, each character must have 16 bits. If UTF 16 can be empty, the supported length is equivalent to two bytes missing, that is, 16 bits missing.

For example, varchar( 16) notnull actually needs 16~48 bytes of storage space, and utf-8 coding is so painful.

The encoding is fixed at 32 bytes. If there are many English characters, it will waste space. All Chinese characters save space)

If varchar( 15) can be null, it actually needs 16~48 bytes of storage space.