This question has already been answered:

What for parameter INT (size) when creating a table, you need to specify the size? Is this the size of the number of valid characters to be written to the column? What is the difference if I write:

So

create table MyTest2(id_use int (1) AUTO_INCREMENT, position5 varchar(10) NOT NULL DEFAULT '0', PRIMARY KEY (id_use)); 

or so

 create table MyTest2(id_use int (100) AUTO_INCREMENT, position5 varchar(10) NOT NULL DEFAULT '0', PRIMARY KEY (id_use)); 

Reported as a duplicate by BOPOH members, Community Spirit Dec 14 '15 at 15:43 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    Most of the answers to such questions are in the documentation.

    As an extension of the ANSI / ISO standard, SQL92 MySQL allows you to specify the number of characters of an integer displayed to the user, if necessary. This optional indication of the number of characters to be output is used to left-up the output values ​​that contain characters less than the specified column width, but does not place restrictions on the range of values ​​that can be stored in a column, or on the number of digits that can be displayed for values which number of characters exceeds the width of this column. If the optional attribute ZEROFILL is additionally specified, the free positions by default are filled with zeros. For example, for a column declared as INT (5) ZEROFILL, the value 4 is extracted as 00004.

    It should be noted that if a value is stored in a column for integers with the number of characters exceeding a predetermined column width, problems may arise when MySQL will generate temporary tables for some complex links, as in such cases MySQL assumes that the data really fit into the column available width.

    http://phpclub.ru/mysql/doc/numeric-types.html

    • So what is it for? And what is the best value to install? Unclear. Can you explain in simple language? - user22940
    • It is also not clear how best to set this parameter or not to set. Maybe leave it as it is? but then the question arises whether it will not be too many resources ... In general, nothing is absolutely clear. - user22940
    • one
      Roughly speaking, this means alignment when outputting for example on the same console, no more. Do you use the console while working with MySql? If yes, then you can see the difference, if not, and you do not need ZEROFILL, then just ignore this parameter and do not specify it. - Alex Krass
    • one
      @semiromid is not a size, it is a fill handle. Yes, just do not specify. This is done for those who use special console utilities and affects solely the appearance for the user in these utilities. The default is 11, so that all the numbers are externally displayed in them. - Alex Krass
    • one
      @semiromid, if you have knowledge of C, C ++, Java, PHP, you can get an analogy with the printf function that formats numbers when outputting to the console: printf("%.11d", value); . In addition to the visual presentation does not affect anything and it is better to leave the default for those who may want to view the data through the console. - Alex Krass

    Do not install any size. Stay close to the standard:

     create table test_int(id int, id1 int(1), id5 int(5)); insert into test_int values (666666,666666,666666); select * from test_int; 

    It seems to me a bad tone to mix storage and formatting.

    • So stop! If no size is set, then it is installed by default. By default, it is - 11 - user22940
    • Eleven what? Depends on the implementation, but usually int - 4 bytes smallint - 2 bytes bigint - 8 bytes - msi
    • default is id1 int (11) if you do not specify int () - user22940