MySQL integer type description int (one) vs int (20)

Source: Internet
Author: User

The integer type is followed by the width of the display. m indicates the maximum display width. The maximum effective display width is 255. The display width is independent of the range of values that the storage size or type contains.

To practice the truth:

Mysql> CREATE TABLE test2 (a int, b int (unsigned) not NULL, C int (+) unsigned zerofill) engine = InnoDB;

Query OK, 0 rows affected (0.06 sec)

Mysql> Show CREATE TABLE test2;

+-------+------------------------------------- --------------------------------------------------------------------------------------------------------------- -------------------+

| Table | Create Table                                                                                                                                                                |

+-------+------------------------------------------------------------------------------------------------------ -----------------------------------------------------------------+

| Test2 | CREATE TABLE ' Test2 ' (

' A ' int (one) DEFAULT NULL,

' B ' int (unsigned) is not NULL,

' C ' int (+) unsigned zerofill DEFAULT NULL

) Engine=innodb DEFAULT Charset=utf8 |

Inserts a record into a table.

mysql> INSERT INTO test2 values (1, 2000000, 34823424);

Query OK, 1 row affected (0.04 sec)

Mysql> select * from Test2;

+------+---------+------------------------------------------+

| A | B | C |

+------+---------+------------------------------------------+

| 1 | 2000000 | 0000000000000000000000000000000034823424 |

+------+---------+------------------------------------------+

Mysql> ALTER TABLE test2 add d int (n) not null;

ERROR 1439 (42000): Display width out of range for column ' d ' (max = 255)

From the above test can be described below:

1: For shaping data types, the number of bytes that the data store occupies is fixed-length. Like what

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

which

m indicates the maximum display width. The maximum effective display width is 255. When the inserted table's field data length is less than the maximum length of the set int (M), the retrieved data is automatically added to the space.

2:zerofill (0), when the actual length of the inserted data is less than the length set when the table is built, it will be 0 from the left. This modifier can prevent MySQL from storing negative values.

3: When the table is built, do not specify the display length of int, the system will automatically preset the display length size.

MySQL integer type description int (one) vs int ()

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.