表结构
Table: t1 Create Table: CREATE TABLE `t1` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ze` int(5) unsigned zerofill DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
insert into t1 (ze) values (123); select * from t1;
执行结果
+----+-------+ | id | ze | +----+-------+ | 1 | 00123 | +----+-------+
显示5位数,以0补齐位数
insert into t1 (ze) values (123456); select * from t1;
执行结果
+----+--------+ | id | ze | +----+--------+ | 1 | 00123 | | 2 | 123456 | +----+--------+
正常插入123456,不会补0
1.对于整型数值,默认是有符号数,当对字段添加zerofill属性后,字段的类型会变成unsigned类型。
2.字段 类型(长度) 只有添加了zerofill属性,长度才会有效
3.字段 类型 zeroflll,不指定长度是,使用该类型的默认长度