MySQL numeric type, time

Source: Internet
Author: User

Numeric Type

integer Type  tinyint  smallint  Mediumint  Int|integer bigint  

Attention:

1, how to choose the data type, our principle is: enough on the line! As much as possible to choose to occupy the small memory of the integral type, but also more efficient!

2, you can use unsigned to control whether there is a sign bit, if not write, the default value is signed

MySQL does not perform automatic type conversion, if the range of the specified type is exceeded, an error will be given directly!

3, you can specify the minimum width of the data display in order to achieve the purpose of uniform display, the general practice is to use zerofill to fill

If the inserted data exceeds the specified display width and does not affect the original data, how to display it:

4, in fact, in MySQL , there is a bool type, but in fact is the alias of tinyint (1) !

decimal Type can also be divided into floating point and fixed point number!

floating point number divided into single-and double-precision type! Where single precision accounted for 4 bytes, and double precision accounted for 8 bytes!

The effective bit of single precision is between 6-7 bit, while the effective bit of double precision is between 16-17 bit! Therefore, we should also note when inserting floating-point numbers, sometimes not exceeding the range of floating-point numbers, but exceeding the precision of floating-point numbers!

Note: 1, the floating-point number also supports the control of the range of numbers, the syntax is:type (m,d) here the type refers to Float or double!

M: Represents the range of all numeric digits (including integers and fractional parts, excluding decimal points)D: Arange that represents the number of decimal places, and the portion of the fractional excess is rounded

2, as with PHP , floating-point numbers also support scientific notation

fixed -point numbers are stored with fixed-point numbers! Key Words: decimal

fixed-point number policy: each time there is a continuous 9 -digit number, it is stored separately with 4 bytes, and the integer and fractional parts are stored separately!

fixed-point number pros and cons:  Advantage: All data will be stored accurately and will not result in loss of data! Cons: Large space occupancy

Note: 1, decimal same support decimal (m,d syntax at this time, M d represents the number of decimal places, by default, m For 10 d 0

2, decimal also supports zerofill syntax since currency values tend to be decimal , decimal Type is also known as currency type!

Date-Time type

datetime and the timestamp

The display and insertion forms of datetime and timestamp are essentially the same, except that the storage form and the range of dates that can be represented are different, in timestamp Medium storage is an integral type, but its display form and insertion form are the same as datetime and date

Note:  when inserting data can support any format, use what delimiter is not important, date range and format is important!

     In addition, you can use a function inside MySQL now () to insert, meaning that the current month and day seconds

Date equivalent to a "subset" of DateTime, only the year and day no time and seconds!

The time type has two meanings:1, the Day of the month ( that is, a "subset" in DateTime, only seconds and minutes)

              2, representing the time interval, the time interval, the format is,D HH:MM:SS that is days : minutes: Seconds

Year only the year, but the year can be abbreviated, such as the reality of 98 Year is considered 1998 years! The range is small, can only be 1901 years to 2155 years, because only a single byte!

Note: If the year is only two bits, greater than or equal to the 19XX years, less than equal to the representative of the 20XX year!

MySQL numeric type, time

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.