MySQL Database operations 4-data type

Source: Internet
Author: User

Integral type data:

1.tinyint,

2.smallint,

3.mediumint,

4.int,

5.bigint.

Invasive

When the statement was made, we found that there was a statement:

Create Table main_t (    tinyint    ),smallint(),    meidum_id mediumint (    ),int(a),      bigint());

This

The 12 inside the brackets is the limit of the width of the data, but does not affect the display, mainly limited to:

1. The display width is the width of the data displayed at the end of the terminal, but it can still be fully displayed if the data does not exceed the display width when the type represents the range.

2. Does not affect memory, is the width regardless of how much, memory allocation will never change, for example, int is 4 bytes, that is, using 100 display width, is also 4 bytes.

Other

Note that the default width is used when the display width is not specified.

Floating point and fixed point number:

1.float,

2.double,

3.decimal.

Here the decimal is the fixed-point number type, declaration of precision M and scale d (scale), the number of bytes stored in relation to M, is m+2 bytes. The fixed-point number is (10,0) by default, and floating-point numbers can declare precision without parentheses.

The following statement:

Create Table float_t (    float (5,1),    double (5, 1 ),    decimal(5,1));

Insert data:

Insert  into Values (5.12,5.12,5.123);

You will see a warning when inserting decimal data.

Original

The reason is:

When floating point data is inserted, if the precision is not satisfied will be automatically 4 to 5 in,

When a fixed-point number is inserted, a type conversion produces a warning if the precision is not met (just a warning, not an error).

Attention:

1. General floating-point numbers are prone to precision problems, preferably using fixed-point numbers, such as currency, scientific data, and data that require precision storage.

2. Floating point is computationally easy to produce precision problems, generally do not use floating point number to do subtraction and comparison.

Date and Time:

1.datetime (Yyyy-mm-dd HH:MM:SS),

2.date (YYYY-MM-DD),

3.timestamp (Yyyy-mm-dd HH:MM:SS),

4.time (HH:MM:SS),

5.year (YYYY).

The format of the date and time is in parentheses.

Attention:

Year is represented by a four-bit string or 4-digit number, a 2-bit string or a number, and 00-69 means that 2000-2069,70-99 represents 1970-1999, and one byte is saved.

Time indicates that when the input is meaningless, it is automatically converted to 00:00:00.

Use the now () function to insert system time into your data:

Effect:

As you can see, the default value of the timestamp is the current system time.

The introduction of time is very complicated, and I choose to understand it by use.

String:

char (m), fixed-length non-binary string, m before 1-255, occupies m bytes,

varchar (M), variable length string, l+1 byte, L<m,

Tinytext, minimum string, l+1 byte,

Text, small string, l+2,

Mediumtext, small string, l+3,

Longtext, large string, l+4,

The above L vary.

Enum, enum,

Set, set.

Right

Stator long string char, the space on the right is ignored,

Variable long string varchar, with the end character after the string,

Text is used to hold large pieces of text, such as articles and comments,

Enum needs to provide enumeration values, such as:

field enum (value 1, value 2, ...),

Numbering is easy to access starting from 1, so you can use numbers to access these string values when you insert them.

The set needs to provide a series of values that, when inserted, error warnings for values that are not in these values, merge values that are duplicated in the insert, and arrange the insertion values in the order of the supplied values.

Binary type:

1.bit,

2.binary,

3.varbinary,

4.tinybinary,

5.blob,

6.mediumblob,

7.longblob.

Bit (m) is stored in M-bit,

Binary and varbinary save binary strings,

BLOBs are used for storing large binary data. You can also store binary strings with no character set. Generally used to store images, audio information and other binary files.

Off

In the type selection optimization, there should be a more commonly used standard, in the future when you can experience the use of, or find some items to see.

MySQL Database operations 4-data type

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.