SMALLINT
This page is part of MariaDB's Documentation.
The parent of this page is: Data Types for MariaDB Xpand
Topics on this page:
Overview
Integer from -32768 to 32767 when signed, or from 0 to 65535 when unsigned.
USAGE
SMALLINT[(<display_width>)] [SIGNED | UNSIGNED] [ZEROFILL]
DETAILS
Data Type | Minimum Value | Maximum Value |
---|---|---|
|
|
|
|
|
|
SYNONYMS
The following are synonyms for SMALLINT:
INT2
EXAMPLES
SIGNED
and UNSIGNED
The SMALLINT
data type may be SIGNED
(allowing negative values) or UNSIGNED
(not allowing negative values).
Example of SMALLINT SIGNED
(the default):
CREATE TABLE smallint_signed_example (
description VARCHAR(20),
example SMALLINT SIGNED
);
INSERT INTO smallint_signed_example VALUES
('Zero', 0),
('Forty-Two', 42),
('Minimum', -32768),
('Maximum', 32767);
Example of SMALLINT UNSIGNED
:
CREATE TABLE smallint_unsigned_example (
description VARCHAR(20),
example SMALLINT UNSIGNED
);
INSERT INTO smallint_unsigned_example VALUES
('Zero', 0),
('Forty-Two', 42),
('Minimum', 0),
('Maximum', 65535);
Out-of-Range
A value is considered "out-of-range" when it is too small or too large to be stored in a data type.
When sql_
An example of non-strict out-of-range behavior:
TRUNCATE smallint_signed_example;
-- Disable strict mode or the inserts will fail
SET sql_mode=(SELECT REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''));
INSERT INTO smallint_signed_example VALUES
('Underflow', -32769),
('Overflow', 32768);
SELECT * FROM smallint_signed_example;
+-------------+---------+
| description | example |
+-------------+---------+
| Underflow | -32768 |
| Overflow | 32767 |
+-------------+---------+
TRUNCATE smallint_unsigned_example;
-- Disable strict mode or the inserts will fail
SET sql_mode=(SELECT REPLACE(@@sql_mode, 'STRICT_TRANS_TABLES', ''));
INSERT INTO smallint_unsigned_example VALUES
('Underflow', -1),
('Overflow', 65536);
SELECT * FROM smallint_unsigned_example;
+-------------+---------+
| description | example |
+-------------+---------+
| Underflow | 0 |
| Overflow | 65535 |
+-------------+---------+
SMALLINT ZEROFILL
While Xpand accepts the SMALLINT ZEROFILL
type on table create, the qualifier is ignored and silently dropped:
CREATE TABLE smallint_zerofill_example (
description VARCHAR(20),
example SMALLINT ZEROFILL
);
SHOW CREATE TABLE smallint_zerofill_example\G
*************************** 1. row ***************************
Table: smallint_zerofill_example
Create Table: CREATE TABLE `smallint_zerofill_example` (
`description` varchar(20) CHARACTER SET utf8,
`example` smallint(6)
) CHARACTER SET utf8 /*$ SLICES=3 */