liveBook · Manning

Number type

As explained in Grokking Relational Database Design

NUMERIC is an SQL exact numeric data type that stores numbers with a declared precision and scale.

NUMERIC is an exact numeric data type for values that need controlled accuracy. Its declaration sets precision, the total number of significant digits, and scale, the number of digits stored to the right of the decimal point. section 4.7

Use NUMERIC for fixed-point values such as money, where small rounding differences can become costly. In many database systems, NUMERIC and DECIMAL have no real differences, so either type may be suitable after checking the system's documentation. section 4.7

Read a declaration such as NUMERIC(8, 2) in two parts:

  • 8 is the precision: the total number of digits allowed. section 4.7
  • 2 is the scale: the number of digits allowed to the right of the decimal point. section 4.7
  • Choose the scale to match the required accuracy; monetary values commonly use 2 places for cents, while larger operations may need more. section 4.7

A recommended price

For a spaceship entity, define recommended_price as NUMERIC(8, 2). This allows eight digits in total and two digits after the decimal point, providing an exact fixed-point representation for the price. section 8.5 section 4.7

Reading a decimal value

The value 12.3456 has precision 6 and scale 4. This example separates the total digit count from the count of fractional digits. section 4.7

How Grokking Relational Database Design covers it

How deep it goes
Explains precision, scale, fixed-point accuracy, and type selection, without descending into storage internals.
Examples
Uses 12.3456, product prices and costs, and a spaceship recommended price declared as NUMERIC(8, 2).
What it assumes
Introduces precision and scale while assuming only basic awareness of database attributes and data types.
What you can do after
Apply it to model monetary and other accuracy-sensitive attributes with an intentional precision and scale.
How it connects
Connects NUMERIC with precision, scale, DECIMAL, fixed-point data types, monetary attributes, and database design.

Also explained in

Compare how 6 books explain number type →

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.