INT

INT is a data type that represents a 32-bit signed integer. It can store numbers ranging from -2,147,483,648 to 2,147,483,647.

Syntax

INT

Example

-- Convert string to integer
SELECT CAST('5' AS INT);

-- Directly input number, the system will automatically convert to integer
SELECT +1;

-- Combine with other numerical calculations
SELECT 3 * 4 + 2;

-- Store in table
CREATE TABLE example (
    id INT ,
    name VARCHAR(255)
);

-- Insert data
INSERT INTO example (id, name) VALUES (1, 'Alice');

-- Query data
SELECT * FROM example;

Precautions

  • When using the CAST function to convert data of other types to INT type, if the input data cannot be converted to an integer, it will return NULL by default.
  • When creating a table, you can specify a column as INT type to store integer values.
  • In queries, you can use INT type values for various calculations, such as addition, subtraction, multiplication, and division.