Data Types in DBMS
Data Types in DBMS
Data Types in DBMS
★ 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)
Type Length Minimum Value Maximum Value Minimum Value Maximum Value
in (Signed) (Signed) (Unsigned) (Unsigned)
Bytes
► 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
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.
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.
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.