MySQL INT

The MySQL INT data type is a fundamental numeric data type used to store whole numbers (integers). It stands for integer and is commonly employed to represent values without decimal points. The INT data type in MySQL has a fixed size and supports both positive and negative integers.

INT introduction

Here are some key characteristics of the MySQL INT data type:

Size and Range

The INT data type in MySQL is a 4-byte (32-bit) integer.
It can store values ranging from -2,147,483,648 to 2,147,483,647 for signed integers.
If you use the UNSIGNED attribute, it can store values from 0 to 4,294,967,295.

Syntax

The syntax for defining an INT column in a table is as follows:

column_name INT;

Storage Space

The INT data type uses a fixed amount of storage space, which can be more efficient than variable-length data types.
The fixed size allows for faster data retrieval and indexing.

Numeric Operations

As an integer type, INT is suitable for mathematical operations like addition, subtraction, multiplication, and division.
It is commonly used for primary key columns, where a unique identifier is required.

Indexing

The INT data type is often used for indexing columns due to its fixed size and efficient storage.
Indexing improves the performance of data retrieval operations, especially in large datasets.

Default Value

If a default value is not specified when creating a column of type INT, it is set to 0 by default.

Example

CREATE TABLE example_table (
    id INT,
    quantity INT UNSIGNED,
    price INT DEFAULT 0
);

In the example above, id is a regular INT column, quantity is an UNSIGNED INT column, and price is an INT column with a default value of 0.

In summary, the MySQL INT data type is a reliable choice for storing whole numbers within a specified range. It offers efficient storage, supports mathematical operations, and is commonly used for primary key columns and indexing. Understanding the characteristics and usage of the INT data type is crucial for designing efficient and effective database schemas.