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 with UNSIGNED.

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

The next generation of charts.

Coming soon.

The next generation of charts. Coming soon.

The next generation of charts. Coming soon.

Fast. Opinionated. Collaborative. Local-first. Keyboard centric. Crafted to the last pixel. We've got 50 slots for Alpha access.