Syntax error int(5) vs. int(10) in MySQL?

int(5) vs. int(10) in MySQL?



The value in the parentheses is used to display only the width and sets the zerofill. The width is 5 for int(5), whereas 10 for int(10). Let us see another example with a different width value set for int.

Let us first create a table. Here, we have set the int to int(11) and int(13). The following is the query to create a table −

mysql> create table intVsIntAnyThingDemo
−> (
−> Number1 int(11) unsigned zerofill,
−> Number int(13) unsigned zerofill
−> );
Query OK, 0 rows affected (1.17 sec)

Now you can insert record in the table with the help of insert command. The query is as follows −

mysql> insert into intVsIntAnyThingDemo values(12345,6789);
Query OK, 1 row affected (0.44 sec)

mysql> insert into intVsIntAnyThingDemo values(3,2);
Query OK, 1 row affected (0.20 sec)

mysql> insert into intVsIntAnyThingDemo values(12,89);
Query OK, 1 row affected (0.15 sec)

mysql> insert into intVsIntAnyThingDemo values(123,6789);
Query OK, 1 row affected (0.17 sec)

mysql> insert into intVsIntAnyThingDemo values(1234,6789);
Query OK, 1 row affected (0.14 sec)

Display all records with the help of select statement. The query is as follows −

mysql> select *from intVsIntAnyThingDemo;

The following is the output displaying zero fill for the total width set for int −

+-------------+---------------+
| Number1     | Number        |
+-------------+---------------+
| 00000012345 | 0000000006789 |
| 00000000003 | 0000000000002 |
| 00000000012 | 0000000000089 |
| 00000000123 | 0000000006789 |
| 00000001234 | 0000000006789 |
+-------------+---------------+
5 rows in set (0.00 sec)
Updated on: 2020-06-29T09:11:10+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements