[MySQL] MySQL data types

MySQL table data storing Size Notes

MySQL specified in any one record (each row of the data table) the theoretical maximum storage capacity of 2 ^ 16 - 1 (Bytes) = 65535 bytes.

FIG MySQL data types Mind

MySQL data type description

1. Numeric

Numeric argument: all values, DBMS into the numeric and decimal integer type.
(DBMS with signed integer numeric type, SQL statements, the default ...... numeric unsigned ...... represents unsigned integer type.)

Integer

tinyint: uses 1 byte to store data, a small integer;
smallint The: use 2 bytes for storing data
mediumint: using 3 bytes stored
int / intege: standard integer, use 4 bytes to store data (common data type)
BIGINT: 8 bytes of data storage, large integers.

Decimal type (float)

float: uses 4 bytes for storage of data
float means that no fractional part
float (M, D) M represents the total length of the data, D represents the fractional part of the length, MD represents an integer part of the length
double: 8 bytes for storing data
double representations no fractional part
double (M, D) M represents the total length of the data, D represents the fractional part of the length, MD represents an integer part of the length

Decimal type (fixed-point)

decimal:
Double no fractional part represents a
double (M, D) M represents the total length of the data, D represents the fractional part of the length, MD represents an integer part of the length

2. The date and time types

datetime: date and time, the format YYYY-mm-dd HH: mm : ss, represents a range from 1000 to 9999, with a value of 0: 0000-00-00 00:00:00
DATE: date, the data portion is datatime
time : time, specify a time, can be negative
year: YYYY format represents a particular year, you can use 2 digits, you can also use 4-digit
timestamp: timestamp, just where the record is updated, the time stamp will be updated into the present time.

3. string type

Fixed strings
char (L): L behalf length, may store the length, in characters, the maximum length of 255.
char (4): In UTF8 environment requires 3 * 4 = 12 bytes

Variable length strings: Depending on the size of the data storage space is allocated
varchar (L): L behalf length, length, theoretical length can be stored in 65536 characters

Text string
text string according to the stored data format can be divided into text and BLOB
text: text character length stored
blob: storing binary data (usually not used)

Enumeration string
enumeration: enum, the future of all possible outcomes data in the fields of design is complete statement when construction of the table in the database, the data is actually stored in the business must be prescribed good data.
Use enumeration
definitions: enum (list elements possible); - such as gender enum ( 'male', 'female', 'secret');
the Create the Table gender_tables (
gender enum ( 'male', 'female' 'Confidential');
) charset UTF8;

Use: can store predefined data. insert into tablename value (......, 'M', ......); enumeration value is actually stored, a field can be enumerated directly inserted into a table number, a string may be inserted.
Or insert into gender value (....., 0 , ......);

String type enumerated principles
enumerated data type used for storing data bytes 1-2. If the DBMS uses 2 bytes for storing data. So any of the enumerated data type DBMS in a maximum amount of 65,536 enumeration options. Actual business data, enumerated data types only a small amount of data. Principle: enumeration value is actually stored, a field can be enumerated directly inserted into the table number. When the construction of the table, when the enumerated data type specification data (the definition), the system will automatically create a corresponding relationship between numbers and enumeration element stored in the log. During insertion of the data, the system automatically converts the character into a corresponding digital stores; when the extracted data, the DBMS automatically convert the data into the corresponding display character string or pass value. If the database is a huge amount of information, the number of records (number of rows in the data table) wide strips, can save a lot of storage space, standardized data. But the system storage efficiency will be reduced.

A collection of strings
set with the data type enumeration data type like: The actual value is stored, not the strings (collections may store a plurality of digital)
enumeration use
definitions: SET (list of elements); - as hobby set ( ' tennis', 'ping-pong', 'swim', 'running');
- in conjunction with each element corresponding to one bit.
Table set_tables Create (
Hobby SET ( 'tennis', 'ping-pong', 'swim', 'running');
) charset UTF8;

Use: can store predefined data. insert into tablename value (......, 'M', ......); enumeration value is actually stored, a field can be enumerated directly inserted into a table number, a string may be inserted.
insert into set_tables value ( 'ping-pong', 'swim', 'running'); insert into set_tables value ( 2 ^ n); see B station mysql proficient video.

 

Guess you like

Origin www.cnblogs.com/Lints/p/11575510.html