Numeric Data Type Overview

General introduction to numeric data types. This page summarizes the available integer, fixed-point, and floating-point types and their storage characteristics.

There are a number of numeric data types:

See the specific articles for detailed information on each.

SIGNED, UNSIGNED and ZEROFILL

Most numeric types can be defined as SIGNED, UNSIGNED or ZEROFILL, for example:

If SIGNED, or no attribute, is specified, a portion of the numeric type will be reserved for the sign (plus or minus). For example, a TINYINT SIGNED can range from -128 to 127.

If UNSIGNED is specified, no portion of the numeric type is reserved for the sign, so for integer types range can be larger. For example, a TINYINT UNSIGNED can range from 0 to 255. Floating point and fixed-point types also can be UNSIGNED, but this only prevents negative values from being stored and doesn't alter the range.

If ZEROFILL is specified, the column will be set to UNSIGNED and the spaces used by default to pad the field are replaced with zeros. ZEROFILL is ignored in expressions or as part of a UNION. ZEROFILL is a non-standard MySQL and MariaDB enhancement.

Note that although the preferred syntax indicates that the attributes are exclusive, more than one attribute can be specified.

Only the following combinations are supported:

  • SIGNED

  • UNSIGNED

  • ZEROFILL

  • UNSIGNED ZEROFILL

  • ZEROFILL UNSIGNED

The latter two should be replaced with simply ZEROFILL, but are still accepted by the parser.

Examples

Range

When attempting to add a value that is out of the valid range for the numeric type, MariaDB will react depending on the strict SQL_MODE setting.

If strict_mode has been set (the default), MariaDB will return an error.

If strict_mode has not been set, MariaDB will adjust the number to fit in the field, returning a warning.

Examples

With strict_mode set:

With strict_mode unset:

AUTO_INCREMENT

The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows. For more details, see auto_increment.

This page is licensed: CC BY-SA / Gnu FDL

Last updated

Was this helpful?