SMALLINT is a numeric data type defined by the SQL standard to hold small whole numbers. It occupies 2 bytes of storage and typically supports a signed range from ‑32,768 to 32,767. Because it uses less space than INT or BIGINT, it is ideal for columns whose values are known to remain within that range, such as age, month number, status codes, or small lookup table identifiers.Behavior- Arithmetic involving SMALLINT follows normal integer math; overflows raise errors or wrap depending on the dialect.- Comparisons, indexing, and joins on SMALLINT columns are generally faster and more memory-efficient than on larger integer types.- In MySQL and MariaDB, SMALLINT can be UNSIGNED (0 to 65,535) and can specify a display width, but display width has no impact starting with MySQL 8.0.- In SQL Server, SMALLINT is always signed and ranges from ‑32,768 to 32,767.- In PostgreSQL, SMALLINT is an alias for INT2 and behaves identically.Caveats- Choosing SMALLINT for a column that later exceeds its range requires an online type change or table rebuild, which can be disruptive.- Some ORMs default to INT, so explicit type mapping may be needed.- Arithmetic promotion rules vary: some engines upcast the result of SMALLINT math to INT to avoid overflow.
SQL-86 (First SQL standard)
SMALLINT occupies 2 bytes (16 bits) of storage regardless of the database engine.
In MySQL or MariaDB append the keyword UNSIGNED: `age SMALLINT UNSIGNED`. Other databases do not support an unsigned modifier for SMALLINT.
Yes. Adding or multiplying values that exceed the SMALLINT range can overflow. Many databases promote the result to INT, but some may raise an error or wrap. Test critical calculations.
Absolutely. SMALLINT columns are often indexed because their small size speeds up B-tree traversals and reduces index storage.