What does INT(7) in MySQL mean?

MySQLMySQLi Database

In INT(7), the number indicates the display width. It does not affect the storage, as we know int takes 4 bytes. It has the range between -2147483648 and 2147483647.

To understand INT(7), let us create a table with zerofill column. The query to create a table is as follows −

mysql> create table DisplayInt
-> (
-> Number int(7) zerofill
-> );
Query OK, 0 rows affected (1.25 sec)

Insert some records in the table using insert command. The query is as follows −

mysql> insert into DisplayInt values(1);
Query OK, 1 row affected (0.12 sec)

mysql> insert into DisplayInt values(12);
Query OK, 1 row affected (0.16 sec)

mysql> insert into DisplayInt values(1234);
Query OK, 1 row affected (0.19 sec)

mysql> insert into DisplayInt values(12345);
Query OK, 1 row affected (0.10 sec)

mysql> insert into DisplayInt values(1234567);
Query OK, 1 row affected (0.18 sec)

Display all records from the table using select statement. The query is as follows.

mysql> select *from DisplayInt;

The following is the output.

+--------+
| Number |
+--------+
| 0000001 |
| 0000012 |
| 0001234 |
| 0012345 |
| 1234567 |
+--------+
5 rows in set (0.00 sec)
raja
Published on 11-Jan-2019 14:17:51
Advertisements