0% found this document useful (0 votes)
95 views

MySQL Data Tape

1. A data type specifies the type of data like integer, string etc. and defines possible values, operations and storage format. 2. MySQL supports numeric, date/time, string and other types. Numeric types include integer and floating-point types. Date/time types represent dates, times and timestamps. String types store variable length text. 3. Data types have attributes like maximum/minimum values, storage size and valid formats that define how values are stored and displayed. Choosing the right type to represent data accurately is important.

Uploaded by

shex zhyar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views

MySQL Data Tape

1. A data type specifies the type of data like integer, string etc. and defines possible values, operations and storage format. 2. MySQL supports numeric, date/time, string and other types. Numeric types include integer and floating-point types. Date/time types represent dates, times and timestamps. String types store variable length text. 3. Data types have attributes like maximum/minimum values, storage size and valid formats that define how values are stored and displayed. Choosing the right type to represent data accurately is important.

Uploaded by

shex zhyar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

What is data type

1. A data type specifies a particular type of data, such as integer, floating-point,


Boolean etc.

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 a number of SQL standard data types in various categories.


MySQL has Numeric Types, the DATETIME, DATE, and TIMESTAMP Types
and String Types. Data types are discussed on this page are based on MySQL
community server 5.6
MySQL Numeric 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)

TINYINT 1 -128 127 0 255

SMALLINT 2 -32768 32767 0 65535

MEDIUMINT 3 -8388608 8388607 to 0 16777215

INT 4 -2147483648 2147483647 0 4294967295

BIGINT 8 - 92233720368 0 184467440737


922337203685477580 54775807 09551615
8
Floating-Point Types

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 allows a nonstandard syntax: FLOAT(M,D) or REAL(M,D) or DOUBLE PRECISION(M,D). Here


values can be stored up to M digits in total where D represents the decimal point. For example, a column
defined as FLOAT(8,5) will look like -999.99999. MySQL performs rounding when storing values, so if you
insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001.
Following table shows the required storage and range (maximum and minimum value for signed and
unsigned integer) for each floating-point type.
Type Length Minimum Value Maximum Value Minimum Value Maximum Value
in Bytes (Signed) (Signed) (Unsigned) (Unsigned)
FLOAT 4 -  -1.175494351E-  1.175494351E- 3.402823466E+38
3.402823466E+38 38 38 
DOUBLE 8 - - 0, and 1.7976931348623
1.7976931348623 2.2250738585072 2.2250738585072 15
157E+ 308 0 0 7E+ 308
14E- 308 14E- 308 
Numeric type attributes

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.

Types Description Display Format Range


DATETIME Use when you need values containing YYYY-MM-DD HH:MM:SS '1000-01-01 00:00:00' to '9999-12-31
both date and time information. 23:59:59'.

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

String length Range


4-digit string '1901' to '2155'.
4-digit number 1901 to 2155.
1- or 2-digit string '0' to '99'. Values in the ranges '0' to '69' and '70' to '99' are
converted to YEAR values in the ranges 2000 to 2069 and
1970 to 1999.
1- or 2-digit number 1 to 99. Values in the ranges 1 to 69 and 70 to 99 are
converted to YEAR values in the ranges 2001 to 2069 and
1970 to 1999.
String Types

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.

Types Description Display Format Range in characters

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.

Types Description Range in bytes


BINARY Contains binary strings. 0 to 255
VARBINARY Contains binary strings. A value from 0 to 255 before MySQL
5.0.3, and 0 to 65,535 in 5.0.3 and later
versions.
BLOB and TEXT Types

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

Types Description Categories Range


BLOB Large binary object that TINYBLOB Maximum length of 255
containing a variable characters.
amount of data. Values are
treated as binary strings.You MEDIUMBLOB Maximum length of
don't need to specify length 16777215 characters.
while creating a column. LONGBLOB Maximum length of
4294967295 characters
BLOB and TEXT Types

TEXT Values are treated as TINYBLOB Maximum length of 255


character strings having a characters.
character set.
MEDIUMBLOB Maximum length of
16777215 characters.

LONGBLOB Maximum length of


4294967295 characters
Thank You

You might also like