Detailed description of mysq-based field selection

Source: Internet
Author: User

Mysql supports many field types, including numeric, date/time, and string (character). storage space and storage efficiency must be taken into account during use;
The following conventions are used for column type descriptions:
· M
The maximum display width. The maximum valid display width is 255.
· D
Time type: datetime (8 bytes), timestamp (4 bytes)
Character Type:
VARCHAR (M), L + 1 byte, where L <= M and 0 <= M <= 65535, it is not recommended to set M too large, because the actual length is calculated in the memory, this computing consumes resources;
CHAR (M) M bytes, 0 <= M <= 255
BINARY (M), MB bytes, 0 <= M <= 255
VARBINARY (M), L + 1 byte, where L <= M and 0 <= M <= 255
ENUM ('value1 ', 'value2 ',...), 1 or 2 bytes, depending on the number of enumerated values (up to 65,535 values). The adjustment is complex and needs to be dropped in create first; when the enumerated value is smaller than 255, it occupies 1 byte, when the value is greater than 255, it occupies 2 bytes;
SET ('value1', 'value2 ',...) 1, 2, 3, 4, or 8 bytes, depending on the number of set members (up to 64 members), 1-8 occupies 1 byte, 9-16 occupies 2 bytes, 17-24 occupies 3 bytes, 25-32 occupies 4 bytes, and 33-64 occupies 8 bytes;
Integer type:
Tinyint (8), one byte
Smallint (16), 2 bytes
Mediumint (24), 3 bytes
Int (32), 4 bytes
Bigint (64), 8 bytes
Real Type:
Float (4 bytes)
Float (M, D) is a single-precision Float, accurate to 6 digits after the decimal point, and double (M, D) is precise to 13 digits after the decimal point;
How to store float memory

Type
Storage bits
Total digits
Offset Value

Digit (S)
Level Code (E)
Tail (M)
(Offset)

Short real number (float)
1
8
23
32
127

Long real number (double)
1
11
52
64
1023

How to store Float
N (10) = 123.456,
Converted to binary representation:
N (2) = 1111011. 01110100101111001
= 1. 11101101110100101111001 (...) * 2 ^ 6
Then E = 127 + 6 = 133 (10) = 10000101 (2)
M = 111 0110 1110 1001 0111 1001 (maximum digit 1 is omitted, total 23bit)
The combination is:
S E M
0 10000101 111 0110 1110 1001 0111

Integer type:
Decimal (M, D) occupies M + 2 bytes, Decimal point and symbol need
Each occupies one byte;
The maximum possible value range of DECIMAL is the same as that of DOUBLE.
But the valid value range is determined by the values of M and D.
Is a string;
Decimal (M, D) occupies M + 2 bytes, And the Decimal point and symbol respectively occupy one byte;
The maximum possible value range of DECIMAL is the same as that of DOUBLE, but its valid value range is determined by the values of M and D. The storage method is string;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.