TINYINT Data Type in MySQL

In MySQL, TINYINT is a data type used to store small integer values. Let’s delve into its specifics and see how it compares to other integer types:
TINYINT
- Storage:
TINYINTUses 1 byte of storage. - Range:
- If signed (allows both positive and negative values):
-128to127 - If unsigned (only non-negative values):
0to255
Comparison with Other Integer Types:
- SMALLINT
- Storage: 2 bytes
- Range:
- Signed:
-32,768to32,767 - Unsigned:
0to65,535
- Signed:
- MEDIUMINT
- Storage: 3 bytes
- Range:
- Signed:
-8,388,608to8,388,607 - Unsigned:
0to16,777,215
- Signed:
- INT or INTEGER
- Storage: 4 bytes
- Range:
- Signed:
-2,147,483,648to2,147,483,647 - Unsigned:
0to4,294,967,295
- Signed:
- BIGINT
- Storage: 8 bytes
- Range:
- Signed:
-9,223,372,036,854,775,808to9,223,372,036,854,775,807 - Unsigned:
0to18,446,744,073,709,551,615
- Signed:
Key Differences:
- Storage Size: The primary difference among these integer types is the amount of storage they use, which ranges from 1 byte for
TINYINTto 8 bytes forBIGINT. - Range: With increasing storage size, the range of values each type can store increases.
TINYINTis suitable for tiny numbers, whileBIGINTcan handle huge numbers. - Use Cases: The choice of integer type often depends on the use case. For instance,
TINYINTmight be used for storing age (assuming age won’t exceed 255) whileBIGINTmight be used for unique identifiers that require a vast range.
When designing a database schema, choosing the appropriate integer type based on the expected range of values is essential to optimize storage and performance.