liveBook · Manning

Smallint

As explained in Grokking Relational Database Design

SMALLINT is a small SQL integer data type with an implementation-defined fixed storage size and numeric range.

SMALLINT is a small integer data type that allocates two bytes of storage. Its minimum and maximum values depend on whether it is signed or unsigned: unsigned values cannot be negative, while signed values can. section 4.6

Choose an integer type by matching the attribute’s possible values to the type’s capacity:

  • Examine requirements and sample data before selecting a type. section 4.6
  • Use numeric IDs when stable, unique, simple, and efficient identifiers fit the design. section 4.6
  • Reject SMALLINT when the expected population can exceed its available range; choose a larger integer type instead. section 4.6

Choosing a type for payment_id

For a payment_id attribute, TINYINT is too small. A galaxy-wide online store would also outgrow SMALLINT, whereas INT is considered large enough for now and BIGINT provides more capacity. section 4.6

How Grokking Relational Database Design covers it

How deep it goes
Defines two-byte storage and signedness, then stops short of specifying an exact numeric range.
Examples
Uses payment_id and a galaxy-wide online store to compare TINYINT, SMALLINT, INT, and BIGINT.
What it assumes
Assumes requirements and sample data, while defining signed and unsigned integers before type selection.
What you can do after
Evaluate integer attributes and choose a type by comparing expected values with available capacity.
How it connects
Connects SMALLINT to integer data types, signed and unsigned integers, numeric IDs, and database attributes.

Also explained in

Compare how 3 books explain smallint →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Relational Database Design. The section links point to the parts of the book it draws on.