Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2004
    Posts
    10

    Unanswered: int(M) in mysql - What does M mean?

    Just wonder, what means have number M at the field declaration like
    field_name INT(M) ?

    I have used to use it as length in bytes, mannual claim, that
    M indicates the maximum display width for integer types
    , but simple tests doesn't show any difference between int(1), int(3), int(5), int(11).

    So basically, what does that number mean?

  2. #2
    Join Date
    Mar 2004
    Posts
    480
    Gee it's like you found all the mysql forums today. ;-)
    See this item

  3. #3
    Join Date
    Nov 2006
    Location
    Quebec
    Posts
    172
    I think that the M digit, is only used for the ZEROFILL parameter, so if you do not use the zerofill, you should only use INT or INT(11) wich is the default.

    NB: You better validate this info, I'm not sure about it.
    Less is more.
    How long is now?
    http://www.lesouterrain.com

  4. #4
    Join Date
    Nov 2006
    Location
    Quebec
    Posts
    172
    CREATE TABLE testTable (
    `a` INT(11),
    `b` INT(11) ZEROFILL
    );
    INSERT INTO testTable (`a`, `b`) VALUES (1, 1);
    SELECT * FROM testTable;

    With this Query you should see the difference
    Less is more.
    How long is now?
    http://www.lesouterrain.com

  5. #5
    Join Date
    Nov 2004
    Posts
    10
    thank you guys for the your help, all is clear for me now

  6. #6
    Join Date
    Mar 2004
    Posts
    480
    INT(11) is not the default INT is. Any GUI that automatically assigns a length value to numeric data types is doing so incorrectly and really gives people the wrong idea about what values can be held in the data type.

  7. #7
    Join Date
    Nov 2006
    Location
    Quebec
    Posts
    172
    but if I specify INT as a datatype in mySql, and then I export the table, it will export my INT field as INT(11)...
    Less is more.
    How long is now?
    http://www.lesouterrain.com

  8. #8
    Join Date
    Mar 2007
    Location
    636f6d7075746572
    Posts
    770
    As you rightly quoted from the MySQL manual :
    M indicates the maximum display width for integer types
    This means that any integer number that displays BELOW this width (as example: 4) will be padded with spaces (or if zerofill specified 0's) ,
    Code:
    CREATE TABLE testTable (
    `a` INT(4),
    `b` INT(4) ZEROFILL
    );
    INSERT INTO testTable (`a`, `b`) 
    VALUES (1, 1)
          ,(12,12)
          ,(123,123)
          ,(1234,1234)
          ,(12345,12345);
    will actually be producing :
    Code:
       a  ||   b
    =============
        1 || 0001
       12 || 0012
      123 || 0123
     1234 || 1234
    12345 || 12345
    note in column `a` you have 3,2,1,0,0 spaces in front of your number

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •