The difference between an int (1) and an int (10) in MySQL

Source: Internet
Author: User

int[(M)] [UNSIGNED] [Zerofill]

An integer of normal size. The signed range is 2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

Int (1) and int (10) have no difference in themselves, but with the (M) value, there will be a display width setting.

As shown in the code:

Mysql> CREATE TABLE test (ID int (3)); Query OK, 0 rows affected (0.47 sec) mysql> insert into test values (12); Query OK, 1 row affected (0.12 sec) mysql> insert into test values (1234); Query OK, 1 row affected (0.10 sec) mysql> SELECT * FROM test;+------+| ID   |+------+|   12 | | 1234 |+------+

Try again. Let's add the Zerofill.

Mysql> CREATE TABLE test1 (ID int (3) zerofill); Query OK, 0 rows affected (0.32 sec) mysql> INSERT into Test1 value (12); Query OK, 1 row affected (0.07 sec) mysql> insert into Test1 value (1234); Query OK, 1 row affected (0.05 sec) mysql> select * FROM test1;+------+| ID   |+------+|  012 | | 1234 |+------+

Note that the 12 front output is more than a 0,int (M) value more than 0, which is the limit of the display width. And more out of it will show up. Only the system to determine the 12 display width is insufficient, will fill the total display width

But be careful when inserting negative numbers:

Negative number is displayed when Zerofill is not set

mysql> INSERT into Test value (-1234); Query OK, 1 row affected (0.07 sec) mysql> select * from test;+-------+| ID    |+-------+|    | |   123 | | -1234 |+-------+3 rows in Set (0.00 sec)

Let's take a look at setting Zerofill:

mysql> INSERT into Test1 value (-1234); Query OK, 1 row affected, 1 warning (0.11 sec) mysql> select * FROM test1;+------+| ID   |+------+|  012 | | 1234 | |  |+------+

The output is 000, and the insertion is-1234. The display is 000.

Originally added Zerofill when the system will automatically add the unsigned property. is a non-negative number. The display width is set to 3 bits. So it will output 000.

The difference between an int (1) and an int (10) in MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.