0% found this document useful (0 votes)
14 views5 pages

MySQL Data Types

The document outlines the various data types available in MySQL, categorized into numeric, string, and date types, along with their storage requirements and value ranges. It explains specific types such as INT, VARCHAR, and DATE, detailing their characteristics and usage scenarios. Additionally, it covers other data types like BLOB and ENUM, highlighting their applications and limitations in database design.
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)
14 views5 pages

MySQL Data Types

The document outlines the various data types available in MySQL, categorized into numeric, string, and date types, along with their storage requirements and value ranges. It explains specific types such as INT, VARCHAR, and DATE, detailing their characteristics and usage scenarios. Additionally, it covers other data types like BLOB and ENUM, highlighting their applications and limitations in database design.
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
You are on page 1/ 5

Data types in MySQL

Introduction
Choosing the right data type for each column of a table will make our database
have optimal performance in the medium and long term.

Below are the three main groups used to store data. As well as
the types that are commonly used to represent each type.

Numeric
Int
Float
2. Strings
Varchar
●Text
3. Date
●Date
DateTime

Data types
List of each type of data, its disk occupancy and values.

Numerical
Enteros
Minimum
Storage Minimum Value Value Maximum Value Maximum Value
Type (Bytes) Signed Unsigned Signed Unsigned
TINYINT 1 -128 0 127 255
SMALLINT 2 -32,768 0 32,767 65,535
MEDIUMINT 3 -8,388,608 0 8,388,607 16,777,215
INT 4 -2,147,483,648 0 2,147,483,647 4,294,967,295
BIGINT 8 -263 0 263 -1 264 -1
Real
DECIMAL (NUMERIC)
The DECIMAL and NUMERIC types store exact numeric data values. These types are used
when it is important to preserve exact precision, for example, with monetary data. In MySQL,
NUMERIC is implemented as DECIMAL, so the following observations about DECIMAL are
they apply equally to NUMERIC.

The maximum number of digits for DECIMAL is 65, but the actual range for a DECIMAL column
determined may be restricted by the precision or scale of a given column. When to
this column is assigned a value with more digits after the decimal point than allowed by the
specified scale, the value is converted to that scale. (The precise behavior is specific to
operating system, but generally the effect is truncation to the allowed number of digits).

Example:
salaryDECIMAL(5,2)

Float, Double
The FLOAT and DOUBLE types represent approximate values of numeric data. MySQL uses four
bytes for single precision values and eight bytes for double precision values. The numbers of
Floating point have limited precision. Although it depends on the operating system.

Because floating-point values are approximate and are not stored as exact values,
attempts to treat them as exact in comparisons can cause problems. They are also
subject to platform or implementation dependencies.

BIT (BOOL, BOOLEAN):


Integer number with a value of 0 or 1.

String
CHAR
Fixed occupation whose length ranges from 1 to 255 characters.

VARCHAR
Variable occupation whose length ranges from 1 to 255 characters.

The maximum allowed length was 255 characters until MySQL 5.0.3. But since this version changed.
up to a maximum of 65,535 characters.

BLOB
BLOBs (Binary Large Objects) are elements used in databases.
to store large-size data that changes dynamically.

Generally, this data consists of images, sound files, and other multimedia objects;

TINYBLOB
A maximum length of 255 characters. Valid for binary objects such as a text file,
images, audio or video files. It does not distinguish between lowercase and uppercase.
BLOB
A maximum length of 65,535 characters. Valid for binary objects such as a text file,
images, audio or video files. It does not distinguish between lowercase and uppercase.

MEDIUMBLOB
A maximum length of 16,777,215 characters. Valid for binary objects such as a file of
text, images, audio or video files. It does not distinguish between lowercase and uppercase.

LONGBLOB
A maximum length of 4,294,967,298 characters. Valid for binary objects such as a file.
text, images, audio or video files. It does not distinguish between uppercase and lowercase.

Lists
Both ENUM and SET are used to determine the values that a field in a table can have.
to say, you can determine that a field can only contain values from a defined list.

SET
Store 0, one or more values from a list with a maximum of 64 possible values.

ENUM
Just like SET but can only store one value.

Text
The main disadvantage of TEXT is that it cannot be easily indexed (unlike VARCHAR).

You cannot assign a default value to a TEXT field (a default value that is
automatically completes if a value has not been provided when inserting a record.

We should only use it for really very long texts, like the ones we mentioned at the beginning.
from this paragraph.

TINYTEXT
A maximum length of 255 characters. It is used to store unformatted plain text. It distinguishes between
lowercase and uppercase.

TEXT
A maximum length of 65,535 characters. It is used to store plain text without formatting. It distinguishes
between lowercase and uppercase.

MEDIUMTEXT
A maximum length of 16,777,215 characters. It is used to store unformatted plain text. It distinguishes
between lowercase and uppercase.

LONGTEXT
A maximum length of 4,294,967,298 characters. It is used to store unformatted plain text.
Distinguish between lowercase and uppercase.
Dates
DATE
Valid for storing a date with year, month, and day, its range is between '1000-01-01' and '9999-12-31'.

DATETIME
Store a date (year-month-day) and a time (hours-minutes-seconds).

Its range is between: '1000-01-01 00:00:00' and '9999-12-31 23:59:59'.

TIME
Valid for storing an hour (hours-minutes-seconds).

Its range of hours ranges from -838-59-59 to 838-59-59. The stored format is 'HH:MM:SS'.

TIMESTAMP
Store a date and time in UTC.
The range of values oscillates between '1970-01-01 00:00:01' and '2038-01-19 03:14:07'.

YEAR
Stores a given year with 2 or 4 digits in length, defaulting to 4. The range of values oscillates between
1901 and 2155 with 4 digits. While with 2 digits the range is from 1970 to 2069 (70-69).

Other types of data


References
They may refer to:
Official documentation at:
oThe provided link does not contain translatable text.
Others
oUnable to access or translate content from the given URL.
oUnable to access the content of the provided URL.

You might also like