1.查看表结构
mysql> show create table student;
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| student | CREATE TABLE `student` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`NAME` varchar(20) NOT NULL,
`AGE` int(11) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 |
+---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.09 sec)
2.添加列
mysql> alter table student add column birthday datetime;
Query OK, 0 rows affected (2.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
3.删除列
mysql> alter table student drop column birthday;
Query OK, 0 rows affected (0.80 sec)
Records: 0 Duplicates: 0 Warnings: 0
4.修改列
--1.修改列的类型
mysql> alter table student modify age int not null;
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
--2.修改列的名称
mysql> alter table student change column name sname varchar(20);
Query OK, 0 rows affected (1.31 sec)
Records: 0 Duplicates: 0 Warnings: 0
参考:
https://www.cnblogs.com/Anidot/articles/7666909.html