Cover Image for MySQL INT
105 views

MySQL INT

The MySQL INT is a data type that is used to store whole numbers. It represents a 32-bit signed integer, which can range from -2,147,483,648 to 2,147,483,647. The INT data type is commonly used to store integer values in database tables.

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

column_name INT;

Here’s an example of creating a table with an INT column:

CREATE TABLE employees (
    employee_id INT,
    first_name VARCHAR(50),
    last_name VARCHAR(50),
    salary INT
);

In this example, the employees table has an employee_id column and a salary column, both of which are of the INT data type. These columns are used to store integer values such as employee IDs and salaries.

MySQL also provides variations of the INT data type that allow you to specify different storage sizes, depending on your specific requirements:

  1. TINYINT: A 1-byte integer, which can store values from -128 to 127 (signed) or 0 to 255 (unsigned).
  2. SMALLINT: A 2-byte integer, which can store values from -32,768 to 32,767 (signed) or 0 to 65,535 (unsigned).
  3. MEDIUMINT: A 3-byte integer, which can store values from -8,388,608 to 8,388,607 (signed) or 0 to 16,777,215 (unsigned).
  4. BIGINT: An 8-byte integer, which can store very large values, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (signed) or 0 to 18,446,744,073,709,551,615 (unsigned).

The choice of which integer type to use depends on the range and precision required for your data. For most applications, the INT data type is sufficient for storing whole numbers, and it provides a good balance between storage size and range.

If you need to store smaller or larger integers, you can select the appropriate integer type based on your specific needs. Additionally, MySQL provides both signed and unsigned variations of these integer types, which affect the range of values that can be stored.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS