
Your data, our passion.
Snack-Sized Data Basics
Data Types - Whole Numbers
Whole numbers in a database are used for counting records, and serving as identifiers (IDs).
​
For example, if you had a water bottle inventory, whole numbers track the quantity of bottles available.
​
​

​
There are different types of whole number data types used in SQL. Here are a few:​
-
INTEGER is the most commonly used data type for whole numbers. It ranges from -2,147,483,648 to +2,147,483,647 and uses 4 bytes worth of space.
-
SMALLINT is used for very small numbers, between -32,768 to 32,767 and uses 2 bytes.
-
BIGINT is used for larger numbers, ranging from -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 and uses 8 bytes.
To save space in your database, it's important to choose a data type that can accommodate the largest number you anticipate, without unnecessarily using a bigger type.
Question:
What data type from the options above would you use if you needed to store population numbers by state?
​
Answer:
A quick google search shows that the largest state population is around 39,000,000. SMALLINT wouldn’t be sufficient, and BIGINT would be unnecessary. INTEGER is the most appropriate choice, and even provides room to grow.​​​
​
​
In a school, whole numbers are used to assign IDs to each student.
