bg-leaves
bg-leaves
Trail pagesProgramming → Reference → MySQL Data Types
TEXT TYPES
Name Description
CHAR( ) A fixed section from 0 to 255 characters long.
VARCHAR( ) A variable section from 0 to 255 characters long.
TINYTEXT A string with a maximum length of 255 characters.
TEXT A string with a maximum length of 65535 characters.
BLOB A string with a maximum length of 65535 characters.
MEDIUMTEXT A string with a maximum length of 16777215 characters.
MEDIUMBLOB A string with a maximum length of 16777215 characters.
LONGTEXT A string with a maximum length of 4294967295 characters.
LONGBLOB A string with a maximum length of 4294967295 characters.

Brackets allow you to enter a maximum number of characters that will be stored in the column. Example: VARCHAR(255)

CHAR and VARCHAR are probably the most widely used types. CHAR is a fixed length string (255) whereas VARCHAR is a variable length string. CHAR is thus processed faster by the database as VARCHAR columns are of unknown length. In the end it depends on the situation, one saves time and the other saves space.

Using both a CHAR and VARCHAR types in the same table, MySQL will automatically change the CHAR into VARCHAR for compatibility reasons.

BLOB is an acronym for Binary Large OBject. As the name states, the BLOB datatype can store binary data such as images. Both the TEXT and BLOB types are variable length and similar to a larger version of VARCHAR.


NUMBER TYPES
TINYINT( ) -128 to 127 normal
0 to 255 UNSIGNED.
SMALLINT( ) -32768 to 32767 normal
0 to 65535 UNSIGNED.
MEDIUMINT( ) -8388608 to 8388607 normal
0 to 16777215 UNSIGNED.
INT( ) -2147483648 to 2147483647 normal
0 to 4294967295 UNSIGNED.
BIGINT( ) -9223372036854775808 to 9223372036854775807 normal
0 to 18446744073709551615 UNSIGNED.
FLOAT A small number with a floating decimal point.
DOUBLE( , ) A large number with a floating decimal point.
DECIMAL( , ) A DOUBLE stored as a string , allowing for a fixed decimal point.

DATE TYPES
DATE YYYY-MM-DD.
DATETIME YYYY-MM-DD HH:MM:SS.
TIMESTAMP YYYYMMDDHHMMSS.
TIME HH:MM:SS.

MISCELLANEOUS TYPES
ENUM ( ) Short for ENUMERATION which means that each column may have one of a specified possible values. Can hold up to 65,535 different items.
SET Similar to ENUM except each column may have more than one of the specified possible values. Can hold up to 64 items

Jump to the start of this page ↑

[x]