用于存储从零开始的整数的 MySQL 数据类型? [英] MySQL Datatype for storing integers starting from Zero?
问题描述
我必须存储格式为 0091
001
009751
009665
的 isdCodes
> 等在数据库中,初始基本上会从零开始.我尝试使用 int 作为具有无符号属性的数据类型,但它似乎不起作用.哪种数据类型适合存储这种类型的值?
I have to store isdCodes
which is in format 0091
001
009751
009665
etc. in the database, the initial will basically start from zero. i tried using int as datatype with unsigned attribute but it does not seems to work. which datatype is suitable for storing this type of value?
推荐答案
不起作用,因为 IDD 前缀在大多数情况下是
00
,但并非总是如此.大多数情况下它以0
开头,但并非总是如此.
Does not work since IDD prefix is in most cases
00
but not always. It starts in most cases with0
but not always.
由于前导零的数量很重要(即 0091
≠ 091
),在这种情况下我会选择 varchar
.
Since the number of leading zeros matter, (i.e., 0091
≠ 091
), I would go for a varchar
in this case.
如果你真的想使用一些数字类型,我想你可以在数字前面加上一个 1
以保留零,但这会有点麻烦.
If you really want to use some numeric type, I guess you could prepend a 1
in front of the number to keep the zeros, but it would be a bit of a hack.
这篇关于用于存储从零开始的整数的 MySQL 数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!