MySQL Alter 表名、字段名、字段类型
- 修改字段类型
alter table table_a modify column user_id varchar(20);
1
- 修改字段名
alter table table_a change `user_id` `user` varchar(20);
1
- 修改表名
RENAME TABLE `table_a` TO `down_record`;
1
- 新增字段
mysql> alter table capacity add name varchar(32);
Query OK, 0 rows affected (0.13 sec)
mysql> select * from capacity;
+----+----------+------------+---------------------+------+
| id | capacity | date | time | name |
+----+----------+------------+---------------------+------+
| 1 | 180 | 2019-10-26 | 2019-10-30 09:34:48 | NULL |
| 2 | 190 | 2019-10-27 | 2019-10-30 09:34:48 | NULL |
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
reference
- [1]Rizky Fakkel. Rename a column in MySQLopen in new window
- [2]W3cscool. SQL ALTER TABLE 语句open in new window