0

If I set a field in MySQL table as INT so the number I store in it would remove all zero's.
For example, if I have an Id like this 100007431431552 finally it would be saved as 17431431552.
The field options are INT with length 32. So what's the problem?

Any suggestions? Thank you.

4

3 回答 3

1

100007431431552 is too large for an INT.

If you were running in strict mode you'd get an error (Data truncation: Out of range value for column 'id').

Unfortunately MySQL's default behaviour is to avoid any error messages and trying to do something else instead - at the cost of losing data without telling you (that's why 17431431552 stored in your example).

For this kind of values you need to use a bigint:

SQLFiddle: http://sqlfiddle.com/#!2/19505/1

于 2013-03-30T10:39:17.513 回答
1

The MySQL manual says the biggest value for an INT type are 2147483647 (signed) and 4294967295 (unsigned). The maximum values vor a BIGINT type are 9223372036854775807 (signed) and 18446744073709551615 (unsigned). So you should use a BIGINT column type.

于 2013-03-30T10:41:59.097 回答
1

from mysql.com

Type    Storage Minimum Value   Maximum Value
    (Bytes) (Signed/Unsigned)   Signed/Unsigned)
TINYINT 1   -128    127
        0   255
SMALLINT    2   -32768  32767
        0   65535
MEDIUMINT   3   -8388608    8388607
        0   16777215
INT 4   -2147483648 2147483647
        0   4294967295
BIGINT  8   -9223372036854775808    9223372036854775807
        0   18446744073709551615

you can not stroe so large number with INT TYPE.

于 2013-03-30T10:42:02.380 回答