If we want to learn a database well, we must first understand the data types it supports. MySQL supports all standard SQL data types, including three categories: numeric, date, and string. Let’s learn with the editor below.
Numerical types include integer types, fixed-point types, floating-point types, and bit value types. Let’s take a look at the integer type first.
Integer type
The most commonly used one is INT
Fixed-point types
DECIMAL
and NUMERIC
types store precise numeric data values. These types can be used when precise accuracy is maintained. In MySQL, NUMERIC
is implemented as DECIMAL
.
Floating point type
In MySQL, float
represents a single precision value, using 4 bytes to represent it, double
represents a double precision value, represented by 8 bytes.
Bit value type
The bit data type is used to store bit values. The bit(M) type allows M bit values to be stored. M ranges from 1 to 64.
DATE only represents the date. The range is from '1000-01-01' to '9999-12-31'.
DATETIME, represents the combination of date and time. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
TIMESTAMP[(M)], used to represent timestamp. The returned TIMESTAMP value is displayed in the format of 'YYYY-MM-DD HH:MM:SS
', and the width will be fixed to 19 characters.
TIME, only time can be recorded. The range is from '-838:59:59' to '838:59:59'. If it exceeds, the maximum value of 838:59:59 will be displayed.
YEAR[(2|4)], can be used to record a two-digit or four-digit year. The default is four-digit format. In four-digit format, allowed values are 1901 to 2155 and 0000. In two-digit format, allowed values are 70 to 69, representing the years from 1970 to 2069.
The string data types include CHAR, VARCHAR and TEXT.
Character data is composed of any combination of letters, symbols or numbers.
varchar
represents variable-length character data, its length does not exceed 8kb. char
is fixed-length character data with a maximum length of 8kb. Data exceeding 8kb can be stored using the text type.
Recommended tutorial: "MySQL Tutorial"
The above is the detailed content of Take you to understand mysql data types in three minutes. For more information, please follow other related articles on the PHP Chinese website!