bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/SQL/SQL References
SQL•SQL References

SQL Data Types for MySQL, SQL Server, and MS Access

Concept visual

SQL Data Types for MySQL, SQL Server, and MS Access

Pointer walk
two pointers
leftright102132436485116
left=0
right=6
1
3

Start at both ends

SQL Data 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. An SQL developer must decide what type of data that will be stored inside each column when creating a table. The data type is a guideline for SQL to understand what type of data is expected inside of each column, and it also identifies how SQL will interact with the stored data. Always check the documentation! Data types might have different names in different databases. And even if the name is the same, the size and other details may be different! MySQL Data Types (Version 8.4) In MySQL there are three main data types: String, Numeric, and Date and Time.

String Data Types

Data type

Description

CHAR(size)

Formula

A fixed - length string (can contain letters, numbers, and special characters).

size specifies the column length in characters, from 0 to 255. Default size is 1

VARCHAR(size)

Formula

A variable - length string (can contain letters, numbers, and special characters).

size specifies the maximum column length in characters, from 0 to 65535

BINARY(size)

Similar to CHAR(), but stores binary byte strings. size specifies the column length in bytes. Default size is 1

VARBINARY(size)

Similar to VARCHAR(), but stores binary byte strings. size specifies the maximum column length in bytes.

BLOB(size)

A BLOB column with a maximum length of 65535 bytes

Tinyblob

A BLOB column with a maximum length of 255 bytes

Mediumblob

A BLOB column with a maximum length of 16777215 bytes

Longblob

A BLOB column with a maximum length of 4294967295 or 4GB bytes

TEXT(size)

Holds a string with a maximum length of 65535 bytes

Tinytext

A TEXT column with a maximum length of 255 characters

Mediumtext

A TEXT column with a maximum length of 16777215 characters

Longtext

A TEXT column with a maximum length of 4294967295 or 4GB bytes ENUM(val1, val2, val3, ...) A string object that can have only one value, chosen from the list of possible values (val1, val2, val3,..). You can list up to 65535 values. If a value is inserted that is not in the list, a blank value will be inserted SET(val1, val2, val3, ...) A string object that can have zero or more values, chosen from the list of possible values (val1, val2, val3,..). You can list up to 64 values

Numeric Data Types

Data type

Description

Bit(

size )

Formula

A bit - value type.

size indicates the number of bits per value, from 1 to 64. The default value for size is 1.

Tinyint(

size )

Formula

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

size specifies the minimum display width (max display width is 255)

Bool

A value of zero is considered as false, nonzero values are considered as true.

Boolean

Equal to BOOL SMALLINT(

size )

Formula

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

size specifies the minimum display width (max display width is 255)

Next

SQL Keywords Reference