3 个解决方案
#1
alter table 表名 change 字段 字段 int not null;
#2
mysql> desc tx;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| col1 | double | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.06 sec)
mysql> alter table tx modify col1 int;
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc tx;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| col1 | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
#3
alter table tx modify column col1 int;
#1
alter table 表名 change 字段 字段 int not null;
#2
mysql> desc tx;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| col1 | double | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.06 sec)
mysql> alter table tx modify col1 int;
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc tx;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| col1 | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
#3
alter table tx modify column col1 int;