TINYINT
You are viewing an old version of this article. View
the current version here.
Syntax
TINYINT[(M)] [SIGNED | UNSIGNED | ZEROFILL]
Contents
Description
A very small integer. The signed range is -128 to 127. The unsigned range is 0 to 255. For details on the attributes, see Numeric Data Type Overview.
INT1 is a synonym for TINYINT
. BOOL and BOOLEAN are synonyms for TINYINT(1)
.
Examples
CREATE TABLE tinyints (a TINYINT,b TINYINT UNSIGNED,c TINYINT ZEROFILL);
With strict_mode set, the default from MariaDB 10.2.4:
INSERT INTO tinyints VALUES (-10,-10,-10); ERROR 1264 (22003): Out of range value for column 'b' at row 1 INSERT INTO tinyints VALUES (-10,10,-10); ERROR 1264 (22003): Out of range value for column 'c' at row 1 INSERT INTO tinyints VALUES (-10,10,10); SELECT * FROM tinyints; +------+------+------+ | a | b | c | +------+------+------+ | -10 | 10 | 010 | +------+------+------+ INSERT INTO tinyints VALUES (128,128,128); ERROR 1264 (22003): Out of range value for column 'a' at row 1 INSERT INTO tinyints VALUES (127,128,128); SELECT * FROM tinyints; +------+------+------+ | a | b | c | +------+------+------+ | -10 | 10 | 010 | | 127 | 128 | 128 | +------+------+------+
With strict_mode unset, the default until MariaDB 10.2.3:
INSERT INTO tinyints VALUES (-10,-10,-10); Query OK, 1 row affected, 2 warnings (0.08 sec) Warning (Code 1264): Out of range value for column 'b' at row 1 Warning (Code 1264): Out of range value for column 'c' at row 1 INSERT INTO tinyints VALUES (-10,10,-10); Query OK, 1 row affected, 1 warning (0.11 sec) Warning (Code 1264): Out of range value for column 'c' at row 1 INSERT INTO tinyints VALUES (-10,10,10); SELECT * FROM tinyints; +------+------+------+ | a | b | c | +------+------+------+ | -10 | 0 | 000 | | -10 | 10 | 000 | | -10 | 10 | 010 | +------+------+------+ INSERT INTO tinyints VALUES (128,128,128); Query OK, 1 row affected, 1 warning (0.19 sec) Warning (Code 1264): Out of range value for column 'a' at row 1 INSERT INTO tinyints VALUES (127,128,128); SELECT * FROM tinyints; +------+------+------+ | a | b | c | +------+------+------+ | -10 | 0 | 000 | | -10 | 10 | 000 | | -10 | 10 | 010 | | 127 | 128 | 128 | | 127 | 128 | 128 | +------+------+------+
See Also
Comments
Comments loading...
Content reproduced on this site is the property of its respective owners,
and this content is not reviewed in advance by MariaDB. The views, information and opinions
expressed by this content do not necessarily represent those of MariaDB or any other party.