但是当我用这种语法在MySQL中修改某个列的类型时,MySQL会提示语法错误。
不知道在MySQL中怎么用sql语句来修改列的类型呢?
5 个解决方案
#1
ALTER TABLE b MODIFY gg VARCHAR(10)
#2
ALTER TABLE t1 CHANGE b b BIGINT NOT NULL;
#3
ALTER TABLE t1 MODIFY b BIGINT NOT NULL;
#4
alter table b change up up varchar(10);
mysql> desc b;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| foreignName | varchar(45) | YES | | NULL | |
| up | float | YES | | NULL | |
| down | float | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
4 rows in set (0.02 sec)
mysql> alter table b change up up varchar(10);
Query OK, 4 rows affected (0.19 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> desc b;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| foreignName | varchar(45) | YES | | NULL | |
| up | varchar(10) | YES | | NULL | |
| down | float | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql>
#1
ALTER TABLE b MODIFY gg VARCHAR(10)
#2
ALTER TABLE t1 CHANGE b b BIGINT NOT NULL;
#3
ALTER TABLE t1 MODIFY b BIGINT NOT NULL;
#4
alter table b change up up varchar(10);
mysql> desc b;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| foreignName | varchar(45) | YES | | NULL | |
| up | float | YES | | NULL | |
| down | float | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
4 rows in set (0.02 sec)
mysql> alter table b change up up varchar(10);
Query OK, 4 rows affected (0.19 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> desc b;
+-------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+----------------+
| id | int(4) | NO | PRI | NULL | auto_increment |
| foreignName | varchar(45) | YES | | NULL | |
| up | varchar(10) | YES | | NULL | |
| down | float | YES | | NULL | |
+-------------+-------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
mysql>