标签:技术 ima 数值 row int 个数 .com span fill
当我们的数字类型加入了unsigned,就只能存储正数,不能存负数,相对来说存储的数值要大一些。
例子:
CREATE table test ( a INT UNSIGNED, b int UNSIGNED )ENGINE=Innodb;
INSERT test value(1, 4); ## ok
INSERT test value(1, -1); ## 报错提醒 [Err] 1264 - Out of range value for column ‘b‘ at row 1
注意: 如果当我们这里 使用 SELECT b-a FROM test;
[Err] 1690 - BIGINT UNSIGNED value is out of range in ‘(`test`.`test`.`a` - `test`.`test`.`b`)
所以建议不要轻易使用unsiged这个属性。一般我们用int都满足数值的大小,如果不行可以使用bigint
就是给数字类型根据字符的个数前面补零。例如 a int(4); a=1; 结果显示就是 0001
例子:
ALTER TABLE test CHANGE COLUMN b b int(4) UNSIGNED ZEROFILL; # 给b字段加上一个补零的属性
然后selelct * from test;
标签:技术 ima 数值 row int 个数 .com span fill
原文地址:http://www.cnblogs.com/shaoshao/p/6649176.html