MySQL Data Tape
MySQL Data Tape
2. A data type also specifies the possible values for that type, the operations that
can be performed on that type and the way the values of that type are stored.
MySQL data types
MySQL supports all standard SQL numeric data types which include INTEGER,
SMALLINT, DECIMAL, and NUMERIC. It also supports the approximate numeric
data types (FLOAT, REAL, and DOUBLE PRECISION). The keyword INT is a
synonym for INTEGER, and the keywords DEC and FIXED are synonyms for
DECIMAL. DOUBLE is a synonym for DOUBLE PRECISION (a nonstandard
extension). REAL is a synonym for DOUBLE PRECISION (a nonstandard
variation) unless the REAL_AS_FLOAT SQL mode is enabled. The BIT data type
stores bit-field values and is supported for MyISAM, MEMORY, InnoDB, and NDB
tables.
Integer types
SQL standard integer types INTEGER (or INT) and SMALLINT are supported by
MySQL. As an extension to the standard, MySQL also supports the integer types
TINYINT, MEDIUMINT, and BIGINT. Following table shows the required storage
and range (maximum and minimum value for signed and unsigned integer) for
each integer type.
Integer types
Type Length Minimum Value Maximum Value Minimum Value Maximum Value
in Bytes (Signed) (Signed) (Unsigned) (Unsigned)
The FLOAT and DOUBLE types represent approximate numeric data values. MySQL uses four
bytes for single-precision values and eight bytes for double-precision values.
Types Description
FLOAT A precision from 0 to 23 results in a four-byte single-
precision FLOAT column
DOUBLE A precision from 24 to 53 results in an eight-byte double-
precision DOUBLE column.
Floating-Point Types
MySQL supports an extension for optionally specifying the display width of integer data types in
parentheses following the base keyword for the type
Types Description
TYPE(N) Where N is an integer and display width of the type is upto N
digits.
ZEROFILL The default padding of spaces is replaced with zeros. So, for a
column INT(3) ZEROFILL, 7 is displayed as 007.
MySQL Date and Time Types
The date and time types represent DATE, TIME, DATETIME, TIMESTAMP, and YEAR. Each type has a
range of valid values, as well as a “zero” value.
DATE Use when you need only date YYYY-MM-DD '1000-01-01' to '9999-12-31'.
information.
TIMESTAMP Values are converted from the current YYYY-MM-DD HH:MM:SS '1970-01-01 00:00:01' UTC to '2038-01-
time zone to UTC while storing and 19 03:14:07' UTC
converted back from UTC to the current
time zone when retrieved.
Time Type
MySQL fetches and displays TIME values in 'HH:MM:SS' format or 'HHH:MM:SS' format The range of. TIME
values from '-838:59:59' to '838:59:59'. The hours part may be rather large because not only the TIME type
can be used to represent the time of day, i.e. less than 24 hours, but also the passed time or a time of
interval between two events.
The TIME values in MySQL can be recognized in many different formats, some of which can include a
trailing fractional seconds part in up to 6 digits microseconds precision. The range for TIME values is '-
838:59:59.000000' to '838:59:59.000000'.
MySQL explains abbreviated TIME values with colons as the time of the day. Suppose '09:10' means
'09:10:00', not '00:09:10'. MySQL understands the abbreviated values without colons as that, the two
rightmost digits represent seconds. For example, we think of '0910' and 0910 as meaning '09:10:00', i.e. 10
minutes after 9 o'clock but the reality is MySQL understand them as '00:09:10', i.e. 9 minutes and 10
seconds. So, be careful about using abbreviated time in MySQL.
Year Type
The YEAR type is a 1-byte type used to represent year values. It can be declared as YEAR(2) or
YEAR(4) to specify a display width of two or four characters. If no width is given the default is four
characters
YEAR(4) and YEAR(2) have different display format but have the same range of values.
For 4-digit format, MySQL displays YEAR values in YYYY format, with a range of 1901 to 2155, or
0000.
For 2-digit format, MySQL displays only the last two (least significant) digits; for example, 70
(1970 or 2070) or 69 (2069).
Year Type
The string types are CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT,
ENUM, and SET.
CHAR and VARCHAR Types
The CHAR and VARCHAR types are similar but differ in the way they are stored and retrieved.
They also differ in maximum length and in whether trailing spaces are retained.
CHAR Contains non-binary strings. Length Trailing spaces are removed. The length can be any value from 0
is fixed as you declare while creating to 255.
a table. When stored, they are right-
padded with spaces to the specified
length.
VARCHAR Contains non-binary strings. As stored. A value from 0 to 255 before MySQL
Columns are variable-length strings. 5.0.3, and 0 to 65,535 in 5.0.3 and
later versions.
BINARY and VARBINARY Types
The BINARY and VARBINARY types are similar to CHAR and VARCHAR, except that they contain
binary strings rather than nonbinary strings.
A BLOB is a binary large object that can hold a variable amount of data. There are four types of
BLOB, TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum
length of the values they can hold.
The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond
to the four BLOB types and have the same maximum lengths and storage requirements.
BLOB and TEXT Types