TINYINT
TINYINT is an 8-bit signed integer data type that occupies 1 byte of storage space, suitable for storing smaller integer values.
Syntax
BYTE is an alias for TINYINT, used for compatibility with migration scripts from other databases. Aliases are immediately converted to the canonical type during parsing. See Type Aliases for details.
Value Range
| Boundary | Value |
|---|---|
| Minimum | -128 |
| Maximum | 127 |
Literal suffix: Y (e.g., 11Y, -100Y)
Examples
-
Use the TINYINT literal suffix:
Returns:
11 -
Cast integers to TINYINT (boundary values):
Returns:
127,-128 -
Cast a string to TINYINT:
Returns:
100 -
Overflow behavior (out-of-range values return NULL):
Returns:
NULLReturns:
NULL -
NULL value handling:
Returns:
NULL
Notes
- The value range is -128 to 127. A CAST conversion that exceeds this range returns NULL without raising an error.
- The literal suffix is
Y(case-insensitive), e.g.,25Y,-100Y. - For larger integers, use
SMALLINT,INT, orBIGINT. - When TINYINT participates in arithmetic operations, the result type may be automatically promoted to INT to avoid intermediate overflow.
- CAST conversions of invalid strings (e.g.,
'abc') return NULL.
