0% found this document useful (0 votes)
5 views6 pages

MySQL SQL Data Types Explained

The document outlines SQL data types supported by MySQL, categorized into numeric, date and time, and string types. It details various data types such as CHAR, VARCHAR, BLOB, INT, FLOAT, and DATE, along with their specifications and usage. Additionally, it notes that data type names and characteristics may vary across different databases.

Uploaded by

notesharbourgju
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

MySQL SQL Data Types Explained

The document outlines SQL data types supported by MySQL, categorized into numeric, date and time, and string types. It details various data types such as CHAR, VARCHAR, BLOB, INT, FLOAT, and DATE, along with their specifications and usage. Additionally, it notes that data type names and characteristics may vary across different databases.

Uploaded by

notesharbourgju
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SQL Data Types for MySQL

A Data Type specifies a particular type of data, like integer, floating points,
Boolean etc. It also identifies 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 supports a lot number of SQL standard data types in various categories. It
uses many different data types broken into mainly three categories: numeric,
date and time, and string types.

The data type of a column defines what value the column can hold:
integer, character, money, date and time, binary, and so on.
Each column in a database table is required to have a name and a data
type.

Note: Data types might have different names in different database. And
even if the name is the same, the size and other details may be different!

String data types:

Data type Description

CHAR(size) A FIXED length string (can contain letters, numbers, and special
characters). The size parameter specifies the column length in
characters - can be from 0 to 255, right-padded with spaces to the
specified length when stored.. Default is 1.

VARCHAR(size) A VARIABLE length string (can contain letters, numbers, and


special characters). A variable-length string between 1 and 255
characters in length, but it can be 65,535(in that case character
will consider as text). You must define a length when creating a
VARCHAR field. For example, VARCHAR(25).

BINARY(size) Equal to CHAR(), but stores binary byte strings.


The size parameter specifies the column length in bytes. Default
is 1

VARBINARY(size) Equal to VARCHAR(), but stores binary byte strings.


The size parameter specifies the maximum column length in
bytes.

For BLOBs (Binary Large OBjects).


BLOB(size) BLOBs are "Binary Large Objects" and are used to store
large amounts of binary data, such as images or
other types of files.
Holds up to 65,535 bytes of data

TINYBLOB For BLOBs (Binary Large OBjects). Max length: 255 bytes

MEDIUMBLOB For BLOBs (Binary Large OBjects). Holds up to 16,777,215 bytes


of data

LONGBLOB For BLOBs (Binary Large OBjects). Holds up to 4,294,967,295


bytes of data

TEXT(size) Holds a string with a maximum length of 65,535 bytes

TINYTEXT Holds a string with a maximum length of 255 characters

MEDIUMTEXT Holds a string with a maximum length of 16,777,215 characters

LONGTEXT Holds a string with a maximum length of 4,294,967,295


characters
Numeric data types:

Data type Description

A bit-value type. The number of bits per value is specified in size.


BIT(size) The size parameter can hold a value from 1 to 64.
The default value for size is 1.

A very small integer. Signed range is from -128 to 127.


TINYINT(size) Unsigned range is from 0 to 255.
The size parameter specifies the maximum display width (which is 255)

BOOL Zero is considered as false, nonzero values are considered as true.

BOOLEAN Equal to BOOL

A small integer. Signed range is from -32768 to 32767.


SMALLINT(size) Unsigned range is from 0 to 65535.
The size parameter specifies the maximum display width (which is 255).

A medium integer. Signed range is from -8388608 to 8388607.


MEDIUMINT(size) Unsigned range is from 0 to 16777215.
The size parameter specifies the maximum display width (which is 255)
A medium integer. Signed range is from -2147483648 to 2147483647.
INT(size)
Unsigned range is from 0 to 4294967295.
The size parameter specifies the maximum display width (which is 255)

INTEGER(size) Equal to INT(size)

BIGINT(size) A large integer.


Signed range is from -9223372036854775808 to 9223372036854775807.
Unsigned range is from 0 to 18446744073709551615.
The size parameter specifies the maximum display width (which is 255)

A floating point number. The total number of digits is specified in size.


FLOAT(size, d) The number of digits after the decimal point is specified in the
d parameter.

A normal-size floating point number. The total number of digits is


DOUBLE(size, d) specified in size. The number of digits after the decimal point is specified
in the d parameter

An exact fixed-point number. The total number of digits is specified in size.


DECIMAL(size, d) The number of digits after the decimal point is specified in the
d parameter. The maximum number for size is 65.
The maximum number for d is 30. The default value for size is 10.
The default value for d is 0.

Note: All the numeric data types may have an extra option: UNSIGNED. If
you add the UNSIGNED option, MySQL disallows negative values for the
column.
Date and Time data types:

Data type Description

A date. Format: YYYY-MM-DD. The supported range is


DATE from '1000-01-01' to '9999-12-31'

A date and time combination. Format:


DATETIME(fsp) YYYY-MM-DD hh:mm:ss. The supported range is from
'1000-01-01 00:00:00' to '9999-12-31 23:59:59'.

A year in four-digit format. Values allowed in four-digit


YEAR format: 1901 to 2155, and 0000.
MySQL 8.0 does not support year in two-digit format.

You might also like