حی ْ َّ
ْحالر مِْن ْ س ْم
ِباہللْالرَّ م ْٰ
Data Types in DBMS
Group Members
★ Farooq Ahmed (CSC-23F-228)
★ Muhamad Azam (CSC-23F-202)
★ Muhammad Hassan Nawazi (CSC-23F-190)
★ Hafiz Muhammad Laraib (CSC-23F-180)
Introduction
► DBMS MySQL supports a number of SQL standard data types in various categories.
Following Data types are are based on MySQL community server
★ Numeric
★ DATE TIME
★ DATE
★ TIMESTAMP
★ String
Numeric Types
Integer Types
Type Length Minimum Value Maximum Value Minimum Maximum Value
in Bytes (Signed) (Signed) Value (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 -9223372036854775808 92233720368 0 184467440737
54775807 09551615
Floating-Point Types
Type Length Minimum Value Maximum Value Minimum Value Maximum Value
in (Signed) (Signed) (Unsigned) (Unsigned)
Bytes
FLOAT 4 -3.402823466E+38 -1.175494351E-38 1.175494351E-38 3.402823466E+38
DOUBLE 8 -1.7976931348623 -2.22507385850720 0, and 1.797693134862315
157E+ 308 14E- 308 2.22507385850720 7E+ 308
14E- 308
Fixed-Point Types
► In standard SQL the syntax DECIMAL(5,2) (where 5 is the precision and 2 is the scale.) be
able to store any value with five digits and two decimals. Therefore the value range will be from -
999.99 to 999.99. The syntax DECIMAL(M) is equivalent to DECIMAL(M,0). Similarly, the syntax
DECIMAL is equivalent to DECIMAL(M,0). MySQL supports both of these variant forms of
DECIMAL syntax. The default value of M is 10. If the scale is 0, DECIMAL values contain no
decimal point or fractional part.
The maximum number of digits for DECIMAL is 65, but the actual range for a given DECIMAL
column can be constrained by the precision or scale for a given column.
Bit Value Types
► The BIT data type is used to store bit-field values. A type of BIT(N) enables storage of N-bit
values. N can range from 1 to 64.
► To specify bit values, b'value' notation can be used. ‘value’ is a binary value written using
zeros and ones. For example, b'111' and b'10000000' represent 7 and 128, respectively
Date and Time Types
DATETIME, DATE, and TIMESTAMP
Types Description Display Range
Format
DATETIME Use when you need values containing both date and YYYY-MM- '1000-01-01
time information. DD 00:00:00' to '9999-
HH:MM:SS 12-31 23:59:59'.
DATE Use when you need only date information. YYYY-MM- '1000-01-01' to
DD '9999-12-31'.
TIMESTAMP Values are converted from the current timezone to UTC YYYY-MM- '1970-01-01
while storing, and converted back from UTC to the DD 00:00:01' UTC to
current time zone when retrieved. HH:MM:SS '2038-01-19
03:14:07' UTC
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 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'.
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
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 1 to 99. Values in the ranges 1 to 69 and 70 to 99 are converted to YEAR values in the
number ranges 2001 to 2069 and 1970 to 1999.
String Types
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 is Trailing spaces are The length can be any value from
fixed as you declare while creating a removed. 0 to 255.
table. When stored, they are right-
padded with spaces to the specified
length.
VARCHAR Contains non-binary strings. Columns As stored. A value from 0 to 255 before
are variable-length strings. MySQL 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
Types Description Categories Range
BLOB Large binary object that containing TINYBLOB Maximum length of 255 characters.
a variable amount of data. Values
are treated as binary strings.You MEDIUMBLOB Maximum length of 16777215 characters.
don't need to specify length while
creating a column.
LONGBLOB Maximum length of 4294967295 characters
TEXT Values are treated as character TINYBLOB Maximum length of 255 characters.
strings having a character set.
MEDIUMBLOB Maximum length of 16777215 characters.
LONGBLOB Maximum length of 4294967295 characters
Thank you for your Time and
Attention!