如下
mysql> desc a1;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.23 sec)
mysql> alter table a1 modify id int zerofill;
Query OK, 0 rows affected (0.55 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc a1;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id | int(10) unsigned zerofill | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+---------------------------+------+-----+---------+-------+
2 rows in set (0.03 sec)
mysql> alter table a1 modify id int(11) zerofill;
Query OK, 0 rows affected (0.36 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc a1;
+-------+---------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------------------------+------+-----+---------+-------+
| id | int(11) unsigned zerofill | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+---------------------------+------+-----+---------+-------+
2 rows in set (0.03 sec)
mysql> alter table a1 modify id int unsigned;
Query OK, 0 rows affected (0.31 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc a1;
+-------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+-------+
| id | int(10) unsigned | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+------------------+------+-----+---------+-------+
2 rows in set (0.06 sec)
1
misaka19000 2017-08-09 11:49:39 +08:00 via Android
为什么我在外面看标题是 zerofill,到里面就变成 unsigned 了?
|
2
est 2017-08-09 12:19:38 +08:00
因为不用显示 负号 了啊。。
那个 10 11 表示显示宽度。 4294967296 10 个字符 -2147483648 11 个字符。 |
3
MajorAdam 2017-08-09 13:09:47 +08:00
符号位
|
4
LYEHIZRF OP |
5
lanjz 2017-08-09 18:36:21 +08:00
MySQL 那个宽度对数值类型似乎不起作用? int(1) 和 int(10) 能存储的一样啊
|
6
iyangyuan 2017-08-09 20:57:13 +08:00 via iPhone
如果不在数据库里做格式化,这个没什么用吧
|