当前位置:Gxlcms > 数据库问题 > Mysql类型属性

Mysql类型属性

时间:2021-07-01 10:21:17 帮助过:33人阅读

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

2、ZEROFILL 

就是给数字类型根据字符的个数前面补零。例如 a int(4); a=1; 结果显示就是 0001

例子:

ALTER TABLE test CHANGE COLUMN b b int(4) UNSIGNED ZEROFILL; # 给b字段加上一个补零的属性

然后selelct * from test;

技术分享

 

Mysql类型属性

标签:技术   ima   数值   row   int   个数   .com   span   fill   

人气教程排行