In SQL, numeric data types are used to store numerical values.
The specific numeric data types can vary slightly between different database systems (like MySQL, PostgreSQL, SQL Server, etc.), but here are the most common SQL numeric data types:
INT
or INTEGER:
-2,147,483,648
to 2,147,483,647
(signed) or 0
to 4,294,967,295
(unsigned).UserID
: An INT
works well for unique identifiers (up to ~2 billion).Age
: A TINYINT
since age is usually under 150.FollowersCount
: Use BIGINT
if you might exceed 2 billion (think of popular social media accounts).CREATE TABLE products (
product_id INT PRIMARY KEY,
name VARCHAR(100),
quantity_in_stock INT
);
INSERT INTO products VALUES (1, 'Water Bottle', 150);
TINYINT
:
-128
to 127
(signed) or 0
to 255
(unsigned).CREATE TABLE example_tinyint (
age TINYINT
);
INSERT INTO example_tinyint (age) VALUES (25);
SMALLINT
:
-32,768
to 32,767
(signed) or 0
to 65,535
(unsigned)CREATE TABLE example_smallint (
score SMALLINT
);
INSERT INTO example_smallint (score) VALUES (1500);
MEDIUMINT
:
-8,388,608
to 8,388,607
(signed) or 0 to 16,777,215 (unsigned).BIGINT
:
-9,223,372,036,854,775,808
to 9,223,372,036,854,775,807
(signed) or 0
to 18,446,744,073,709,551,615
(unsigned).FLOAT
:
DOUBLE
:
REAL
:
DECIMAL
or NUMERIC
:
DECIMAL(10, 2)
can store numbers up to 10 digits in total, with 2 digits after the decimal point.Data Type | Description |
---|---|
INT |
Standard integer |
SMALLINT |
Small integer |
TINYINT |
Very small integer |
MEDIUMINT |
Medium-sized integer |
BIGINT |
Large integer |
DECIMAL |
Fixed-point number with specified precision |
NUMERIC |
Similar to DECIMAL |
FLOAT |
Floating-point number |
DOUBLE |
Double-precision floating-point number |
REAL |
Similar to FLOAT |
BIT |
Stores binary values |