0
0
MySQLquery~5 mins

Integer types (TINYINT, INT, BIGINT) in MySQL

Choose your learning style9 modes available
Introduction
Integer types store whole numbers in a database. They help save space and organize data by size.
When you need to store small numbers like age or rating (use TINYINT).
When you want to store regular whole numbers like counts or IDs (use INT).
When you expect very large numbers like big counters or large IDs (use BIGINT).
Syntax
MySQL
column_name TINYINT
column_name INT
column_name BIGINT
TINYINT stores very small numbers (-128 to 127 signed).
INT stores medium size numbers (-2,147,483,648 to 2,147,483,647 signed).
BIGINT stores very large numbers (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 signed).
Examples
Use TINYINT for small numbers like age (0 to 255 if unsigned).
MySQL
age TINYINT
Use INT for normal whole numbers like user IDs.
MySQL
user_id INT
Use BIGINT for very large numbers like big counters.
MySQL
big_counter BIGINT
Sample Program
This creates a table with three integer columns of different sizes, inserts one row, and selects it.
MySQL
CREATE TABLE example_numbers (
  small_num TINYINT,
  normal_num INT,
  large_num BIGINT
);

INSERT INTO example_numbers VALUES (100, 200000, 9000000000000);

SELECT * FROM example_numbers;
OutputSuccess
Important Notes
Choosing the right integer type saves space and improves speed.
Unsigned versions store only positive numbers but double the max positive range.
Always pick the smallest type that fits your data to be efficient.
Summary
TINYINT, INT, and BIGINT store whole numbers of different sizes.
Use TINYINT for small numbers, INT for medium, and BIGINT for very large numbers.
Picking the right type helps your database work better and use less space.