What is MySQL INT Data Type?
In MySQL, the INT
data type stores integer values without decimal points, offering a fixed-point solution for whole numbers. Users define columns with this type to accommodate various numeric data within a specified range. Let’s dive further into MySQL’s INT
data type!
What is the syntax for MySQL’s INT
?
To define a column with the INT
data type in MySQL, users employ the following syntax:
column_name INT[(M)] [UNSIGNED] [ZEROFILL]
M
: Specifies the display width, affecting the visual representation without altering the stored range.UNSIGNED
: Optionally signifies that the column accepts only non-negative values, expanding the positive range.ZEROFILL
: Optionally pads the displayed value with zeros up to the defined width, commonly used withUNSIGNED
.
Example
Consider this table creation example:
CREATE TABLE example_table ( id INT, age INT UNSIGNED );
Here, id
is a signed INT
column, while age
is an unsigned INT
column.
Storage requirements
Storage needs for INT
in MySQL differ based on its size:
INT
: Occupies 4 bytes and accommodates values from -2,147,483,648 to 2,147,483,647.INT UNSIGNED
: Also uses 4 bytes but allows values within 0 to 4,294,967,295.
Usage
The INT
data type serves various purposes, including storing counts, IDs, and other numeric data without decimal precision.
Conclusion
MySQL's INT
data type offers a flexible solution for storing integer values within defined ranges. Mastery of its syntax, storage considerations, and usage scenarios is crucial for effective database management and query optimization.
Invite only
We're building the next generation of data visualization.
How to Add Columns to MySQL Tables with ALTER TABLE
Robert Cooper
How to Add Columns to Your MySQL Table
Max Musing
Pivot Tables in MySQL
Robert Cooper
How to Rename a Table in MySQL
Max Musing
How to Optimize MySQL Tables for Better Performance
Robert Cooper
How to Display MySQL Table Schema: A Guide
Jeremy Sarchet