📜  MySQL INT(1)

📅  最后修改于: 2023-12-03 15:17:45.879000             🧑  作者: Mango

MySQL INT

MySQL INT is a data type in MySQL used to store integer values. It can store signed or unsigned integers of different sizes. INT is a commonly used data type in MySQL and is used to store integer values in tables.

Syntax

INT[(M)] [UNSIGNED] [ZEROFILL]

Where:

  • M: Specifies the maximum display width for the integer. Default is 11.
  • UNSIGNED: Specifies that the integer should be unsigned.
  • ZEROFILL: Add leading zeros to the integer value.
Examples
Creating a table with INT column

To create a table with an INT column, use the following syntax:

CREATE TABLE table_name (
    col_name INT
);
Specifying INT size

You can specify the size of the INT column using the M parameter.

CREATE TABLE table_name (
    col_name INT(10)
);
Unsigned INT

You can specify that an INT column should be unsigned using the UNSIGNED keyword.

CREATE TABLE table_name (
    col_name INT UNSIGNED
);
Zerofill INT

You can use the ZEROFILL keyword to add leading zeros to the integer value.

CREATE TABLE table_name (
    col_name INT UNSIGNED ZEROFILL
);
Conclusion

MySQL INT is a common data type used to store integer values. It can store both signed and unsigned integers of different sizes. When creating tables, you can specify the size, whether it should be unsigned, and whether it should have leading zeros. Use the examples provided to help you create your own tables with INT columns.