Data Type For Number In Sql

5 min read

Choosing the right data type for number in SQL is one of those decisions that quietly shapes the health of an entire database. Pick well, and your queries stay fast, your storage stays lean, and your financial reports stay accurate to the last cent. In real terms, pick poorly, and you inherit silent rounding errors, overflow crashes, and tables three times larger than they need to be. This guide walks through every numeric data type you will meet in SQL, explains what each one actually does under the hood, and gives you a practical framework for deciding which one belongs in your next CREATE TABLE statement.

What Are Numeric Data Types in SQL?

Numeric data types define how a database engine stores and processes numbers. Unlike text or date types, numeric types are designed for arithmetic operations: addition, subtraction, aggregation, comparison, and rounding. Every relational database management system (RDBMS) offers a family of numeric types that trade off three things against each other:

  • Range — how large or small a number can be
  • Precision — how many digits are preserved exactly
  • Storage cost — how many bytes each value consumes on disk and in memory

There is no single "best" numeric type. There is only the type that matches the shape of your data Most people skip this — try not to..

The Two Big Families: Exact vs. Approximate

Before diving into individual types, understand the split that matters most.

Exact numeric types store values with full fidelity. DECIMAL(10,2) holding 19.99 will always return 19.99. These include integers and fixed-point decimals.

Approximate numeric types store values in binary floating-point form, which cannot represent many decimal fractions precisely. These include FLOAT, REAL, and DOUBLE PRECISION Simple as that..

The rule of thumb professionals follow: use exact types for anything you count or charge for, and approximate types only for scientific measurements where a tiny error is acceptable.

Integer Types: Whole Numbers, Maximum Speed

Integers store numbers with no fractional component. They are the fastest numeric types to process and the cheapest to store Easy to understand, harder to ignore..

Type Typical Storage Signed Range
TINYINT 1 byte −128 to 127
SMALLINT 2 bytes −32,768 to 32,767
MEDIUMINT (MySQL) 3 bytes −8,388,608 to 8,388,607
INT / INTEGER 4 bytes −2,147,483,648 to 2,147,483,647
BIGINT 8 bytes −9.22 × 10¹⁸ to 9.22 × 10¹⁸

Practical guidance:

  1. Use TINYINT for flags, status codes, and small enumerations (0–255 is plenty for most status columns).
  2. Use SMALLINT for counts that stay small, such as items per order or a person's age.
  3. Use INT as your sensible default for identifiers and ordinary counters.
  4. Use BIGINT for high-volume IDs, timestamps in milliseconds, and anything that might exceed 2.1 billion.

MySQL also supports the UNSIGNED modifier, which doubles the positive range by giving up negatives — useful for IDs and quantities that can never be below zero. PostgreSQL and SQL Server do not have unsigned integers.

DECIMAL and NUMERIC: The Exact Fixed-Point Workhorse

DECIMAL and NUMERIC are synonyms in most engines. They store numbers as an exact value with two parameters:

  • Precision (p) — the total count of significant digits
  • Scale (s) — how many of those digits sit to the right of the decimal point

So DECIMAL(10,2) can hold values up to 99,999,999.DECIMAL(6,3) holds up to 999.But 99 with exactly two decimal places. 999 That alone is useful..

We're talking about the type you want for money, prices, tax rates, measurements, scientific constants, and inventory quantities. SQL Server allows precision up to 38; MySQL allows 65 digits of precision with up to 30 decimal places; PostgreSQL's numeric is effectively unbounded; Oracle's NUMBER(p,s) caps at 38 significant digits.

CREATE TABLE invoice (
    invoice_id   INT PRIMARY KEY,
    subtotal     DECIMAL(12,2) NOT NULL,
    tax_rate     DECIMAL(5,4)  NOT NULL DEFAULT 0.0725,
    total        DECIMAL(12,2) GENERATED ALWAYS AS (subtotal * (1 + tax_rate)) STORED
);

The storage cost is not fixed — DECIMAL uses a variable number of bytes depending on the declared precision, which is why over-declaring precision has a real price.

FLOAT, REAL, and DOUBLE PRECISION: Speed With a Caveat

Approximate types follow the IEEE 754 standard. A single-precision value (REAL, often 4 bytes) gives

FLOAT, REAL, and DOUBLE PRECISION: Speed With a Caveat

Approximate types follow the IEEE 754 standard. A single‑precision value (REAL, often 4 bytes) gives you roughly 7 decimal digits of precision, a usable exponent range of about ±3.4 × 10³⁸, and can represent every integer up to 16 777 215 exactly—because its mantissa contains only five explicit bits. This makes REAL attractive for fast “rough” calculations such as sorting rows by a column that doesn’t require exact cents, but it also means tiny rounding errors accumulate quickly during chains of arithmetic.

In contrast, DOUBLE PRECISION occupies 8 bytes and stores each number as 64 bits. Day to day, it offers ≈15–17 significant decimal digits of fidelity and an exponent range of roughly ±1. Here's the thing — 7 × 10³⁰⁸. Because the mantissa includes 53 bits (≈15–16 decimal digits), most everyday numeric work—calculating tax totals, averages, or interpolated fields—will behave almost like decimal math while remaining far faster than arbitrary‑precision libraries. That said, double‑precision suffers from loss of significance when subtracting two close values (e.g., price_before_tax - price_after_tax) or when dealing with very large magnitudes beyond 10²⁰. For those scenarios, you’ll want to switch to a higher‑range type (such as DECIMAL or BIGINT) or apply careful rounding before performing sensitive computations.

You'll probably want to bookmark this section.

When to Choose Which Type

Situation Recommended Precision
Internal flags, status codes, enumerations (0‑255) TINYINT / UNSIGNED TINYINT
Small counts (items per order, age) SMALLINT
General identifiers, primary keys, ordinary counters INT / INTEGER
Very large IDs, timestamps in milliseconds, any value > 2.1 billion `

At its core, where a lot of people lose the thread.

Hot Off the Press

This Week's Picks

Neighboring Topics

Keep the Thread Going

Thank you for reading about Data Type For Number In Sql. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home