CodesJava

Easy learning with example program codes

Data Types in MariaDB

MariaDB Data Types

A data type represents the type of the data that can be stored and processed. Some common data types include integer, floating point, string, boolean, etc. A data type also specifies the type of operations that can be performed on that type.

MariaDB supports a lot of the standard data types of SQL. These data types are divided into various categories, but most of them fall into three main categories viz. Numeric data type, date and time data type, large object data type and string data type.

 

Numeric Data Types:

There are mainly eighteen numeric data types that MariaDB supports. These are listed below:

Data TypeRangeMaximum widthDescription
BIT-128 to 127(signed)

0 to 255(unsigned)

4 digitsVery small integer values.
INT-2147483648 to 2147483647 (signed)

0 to 4294967295 (unsigned)

11 digitsNormal sized integer value.
INTEGER-2147483648 to 2147483647 (signed)

0 to 4294967295 (unsigned)

11 digitsNormal sized integer value.
TINYINT-128 to 127(signed)

0 to 255(unsigned)

4 digitsVery small integer values.
SMALLINT-32768 to 32767 (signed)

0 to 65535 (unsigned)

5 digitsSmall integer value.
MEDIUMINT-8388608 to 8388607 (signed)

0 to 16777215 (unsigned)

9 digitsMedium sized integer value.
BIGINT-9223372036854775808 to 9223372036854775807 (signed)

0 to 18446744073709551615 (unsigned)

20 digitsLarge integer value.
FLOATSingle precision floating point number.
DOUBLEDouble precision floating point number.
DOUBLE

PRECISION

Double precision floating point number.
DECIMALUnpacked fixed point number.
DECUnpacked fixed point number.
NUMERICUnpacked fixed point number.
FIXEDUnpacked fixed point number.
REALDouble precision floating point number.
FLOATFloating point number.
BOOLEquivalent to TINYINT(1)
BOOLEANEquivalent to TINYINT(1)

 

Date and Time Data Types:

There are mainly five date and time data types that MariaDB supports. These are listed below:

Data TypeRangeFormat
DATE‘1000-01-01’ to ‘9999-12-31’yyyy-mm-dd
DATETIME‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’yyyy-mm-dd hh:mm:ss
TIMESTAMP(m)‘1970-01-01 00:00:01’ UTC to ‘2038-01-19 03:14:07’ UTCYYYY-MM-DD HH:MM:SS
TIME‘-838:59:59’ to ‘838:59:59’HH:MM:SS
YEAR[(2|4)]2 digits or 4 digits value4 digits by default

 

 

String Data Types:

There are mainly eight string data types that MariaDB supports. These are listed below:

Data Type Maximum SizeDescription
CHAR(size)255 charactersHere, size is equal to the number of characters to store. It is used for fixed-length strings with space padded on right to equal size characters.
VARCHAR(size)255 charactersHere, size is equal to the number of characters to store. It is used for variable-length strings.
TINYTEXT(size)255 charactersHere, size is equal to the number of characters to store.
TEXT(size)65,535 charactersHere, size is equal to the number of characters to store.
MEDIUMTEXT(size)16,777,215 charactersHere, size is equal to the number of characters to store.
LONGTEXT(size)4GB or 4,294,967,295 charactersHere, size is equal to the number of characters to store.
BINARY(size)255 charactersHere, size is equal to the number of binary characters to store. It is used for fixed-length strings with space padded on right to equal size characters.
VARBINARY(size)255 charactersHere, size is equal to the number of binary characters to store. It is used for variable-length strings.

 

 

Large Object (LOB) Data Types:

There are mainly four large object or LOB data types that MariaDB supports. These are listed below:

Data TypeMaximum Size
TINYBLOB255 bytes
BLOB(size)65,535 bytes
MEDIUMBLOB16,777,215 bytes
LONGTEXT4GB or 4,294,967,295 characters

 

Please follow and like us:
error









Copyright © 2019 CodesJava DMCA.com Protection Status