MySql更改数据表中,列名以及其属性-写给自己的博客
mysql> desc student_info;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(16) | NO | | NULL | |
| tel | varchar(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+由上可知,数据表为student_info,字段为:id、name以及tel,其相关属性如上表中的Type列的值。下面就以tel字段来说明。现在把tel字段改名为pho,其属性由varchar(11)改为int。
mysql>
alter table student_info change column tel pho int;更改后,表结构如下:
mysql> desc student_info;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(16) | NO | | NULL | |
| pho | int(11) | YES | | NULL | |
+-------+-------------+------+-----+---------+----------------+更改完毕。收工!