Why can't I insert 10 digits when my column is INT(10)

后端 未结 6 1735
孤独总比滥情好
孤独总比滥情好 2021-01-17 05:24

I have this column that\'s INT(10) ZEROFILL NOT NULL DEFAULT \'0000000000\',

But when I insert something like 9100000010, I get 42949

6条回答
  •  野的像风
    2021-01-17 06:11

    It should have allowed 10 digits there, right?

    NO, size of INT and integer types in mySQL is to set the display width when field has ZEROFILL specified.

    for example if the value you inserted is 123456 then when you query it, it will displays as 0000123456 , it is just the display width and doesn't affect the value.

    so the value range is determined by the datatype itself, not the display width. to store greater values, you should change the datatype to a suitable one, like BIGINT.

    from mySQL reference:

    INT : A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295.

提交回复
热议问题