Quick Data Types List

(For a more in depth description see below)

TINYINT
	Range: -128 to 127
	C Variable: signed char (int8_t)

TINYINT unsigned
	Range: 0 to 255
	C Variable: char (uint8_t)

SMALLINT
	Range: -32768 to 32767
	C Variable: short int (int16_t)
 
SMALLINT unsigned
	Range: 0 to 65535
	C Variable: unsigned short int (uint16_t)

MEDIUMINT
	Range: -8388608 to 8388607
	C Variable: short long (int24_t)

MEDIUMINT unsigned
	Range: 0 to 16777215
	C Variable: unsigned short long (uint24_t)

INT
	Range: -2147483648 to 2147483647
	C Variable: int (int32_t)
 
INT unsigned
	Range: 0 to 4294967295
	C Variable: unsigned int (uint32_t)

BIGINT
	Range: -9223372036854775808 to 9223372036854775807
	C Variable: long long int (int64_t)

BIGINT unsigned
	Range: 0 to 18446744073709551615
	C Variable: unsigned long long int (uint64_t)

FLOAT
	Range: 
	C Variable: float

DOUBLE
	Range: 
	C Variable: double

TIME
	Range: 
	C Variable: MYSQL_TIME

DATE
	Range: 
	C Variable: MYSQL_TIME

DATETIME
	Range: 
	C Variable: MYSQL_TIME

TIMESTAMP
	Range: 
	C Variable: MYSQL_TIME

TEXT
	Range: A field with a maximum length of 65535 characters.
	C Variable: char[]

CHAR
	Range: A fixed-length string between 1 and 255
	C Variable: char[]

VARCHAR
	Range: A variable-length string up to 65535 characters in length
	C Variable: char[]
	Length is actually the max length specification.  Whilst you can simply specify a very
	large value of varchar(max) bear in mind the following:
		- Temporary tables and MEMORY tables store a VARCHAR column as a fixed-length column,
		padded out to its maximum length, so there's a possible performance impact.
		- The effective maximum length of a VARCHAR is subject to the maximum row 
		size (65,535 bytes, which is shared among all columns) and the character set used.
		- If using a multi-byte character (e.g. a utf-8 collation) you will not be able to
		create a varchar with about more than 21000 chars (65535 / 3). If you use ascii, you will.
		- varchar(max) can impact performance so avoid if you can.

 
BLOB
	Range: A field with a maximum length of 65535 characters.
	C Variable: char[]
 
BINARY
	Range: A fixed-length byte array between 1 and 255
	C Variable: char[]
 
VARBINARY
	Range: A variable-length byte array between 1 and 255 characters in length
	C Variable: char[]

Numeric

BOOL

Use TINYINT

BIT

The BIT data type is used to store bit-field values. A type of BIT(M) enables storage of M-bit values. M can range from 1 to 64.  (Not universally supported)

INT

A normal-sized integer that can be signed or unsigned. If signed, the allowable range is from -2147483648 to 2147483647. If unsigned, the allowable range is from 0 to 4294967295. You can specify a width of up to 11 digits (this is just a display width with the left being padded with spaces)

TINYINT

A very small integer that can be signed or unsigned. If signed, the allowable range is from -128 to 127. If unsigned, the allowable range is from 0 to 255. You can specify a width of up to 4 digits.

SMALLINT

A small integer that can be signed or unsigned. If signed, the allowable range is from -32768 to 32767. If unsigned, the allowable range is from 0 to 65535. You can specify a width of up to 5 digits.

MEDIUMINT

A medium-sized integer that can be signed or unsigned. If signed, the allowable range is from -8388608 to 8388607. If unsigned, the allowable range is from 0 to 16777215. You can specify a width of up to 9 digits.

BIGINT

A large integer that can be signed or unsigned. If signed, the allowable range is from -9223372036854775808 to 9223372036854775807. If unsigned, the allowable range is from 0 to 18446744073709551615. You can specify a width of up to 11 digits.

FLOAT(M,D)

A floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 10,2, where 2 is the number of decimals and 10 is the total number of digits (including decimals). Decimal precision can go to 24 places for a FLOAT.

DOUBLE(M,D)

A double precision floating-point number that cannot be unsigned. You can define the display length (M) and the number of decimals (D). This is not required and will default to 16,4, where 4 is the number of decimals. Decimal precision can go to 53 places for a DOUBLE. REAL is a synonym for DOUBLE.

DECIMAL(M,D)

An unpacked floating-point number that cannot be unsigned. In unpacked decimals, each decimal corresponds to one byte. Defining the display length (M) and the number of decimals (D) is required. NUMERIC is a synonym for DECIMAL.

INT fields Length value

The length parameter has no effect on how data is stored. It just specifies how many characters to pad when selecting data that is also defined as ZEROFILL. So it’s not important in how the db is used, the length does absolutely nothing unless you use ZEROFILL, where it will determine how many leading zeros are added before a value that is smaller than the length parameter.

Date and Time

DATE

A date in YYYY-MM-DD format, between 1000-01-01 and 9999-12-31. For example, December 30th, 1973 would be stored as 1973-12-30.

DATETIME

A date and time combination in YYYY-MM-DD HH:MM:SS format, between 1000-01-01 00:00:00 and 9999-12-31 23:59:59. For example, 3:30 in the afternoon on December 30th, 1973 would be stored as 1973-12-30 15:30:00.

When adding a DateTime to a table make sure your software hasn’t set “On Update Current_Timestamp” by default otherwise every time there is a an update to the row it will get changed automatically!

TIMESTAMP

A timestamp between midnight, January 1, 1970 and sometime in 2037. This looks like the previous DATETIME format, only without the hyphens between numbers; 3:30 in the afternoon on December 30th, 1973 would be stored as 19731230153000 ( YYYYMMDDHHMMSS ).

TIME

Stores the time in HH:MM:SS format.

YEAR(M)

Stores a year in 2-digit or 4-digit format. If the length is specified as 2 (for example YEAR(2)), YEAR can be 1970 to 2069 (70 to 69). If the length is specified as 4, YEAR can be 1901 to 2155. The default length is 4.

String

CHAR(M)

A fixed-length string between 1 and 255 characters in length (for example CHAR(5)), right-padded with spaces to the specified length when stored. Defining a length is not required, but the default is 1.

VARCHAR(M)

A variable-length string between 1 and 65535 characters in length; for example VARCHAR(25). You must define a length when creating a VARCHAR field. VARCHAR has the advantage over text in that it is stored in the row and can be handled in memory by MySQL, disk based access is not required for queries.

BLOB or TEXT

A field with a maximum length of 65535 characters. BLOBs are “Binary Large Objects” and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.

TINYBLOB or TINYTEXT

A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.

MEDIUMBLOB or MEDIUMTEXT

A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.

LONGBLOB or LONGTEXT

A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.

JSON

MySQL has a JSON column type. MariaDB considers it a LONGTEXT instead.

ENUM

An enumeration, which is a fancy term for list. When defining an ENUM, you are creating a list of items from which the value must be selected (or it can be NULL). For example, if you wanted your field to contain “A” or “B” or “C”, you would define your ENUM as ENUM (‘A’, ‘B’, ‘C’) and only those values (or NULL) could ever populate that field.

Files

BLOB

A field with a maximum length of 65535 characters. BLOBs are “Binary Large Objects” and are used to store large amounts of binary data, such as images or other types of files. Fields defined as TEXT also hold large amounts of data; the difference between the two is that sorts and comparisons on stored data are case sensitive on BLOBs and are not case sensitive in TEXT fields. You do not specify a length with BLOB or TEXT.

TINYBLOB

A BLOB or TEXT column with a maximum length of 255 characters. You do not specify a length with TINYBLOB or TINYTEXT.

MEDIUMBLOB

A BLOB or TEXT column with a maximum length of 16777215 characters. You do not specify a length with MEDIUMBLOB or MEDIUMTEXT.

LONGBLOB

A BLOB or TEXT column with a maximum length of 4294967295 characters. You do not specify a length with LONGBLOB or LONGTEXT.

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *