首页 > 数据库技术 > 详细

程序媛计划——mysql修改表结构

时间:2017-09-09 10:37:42      阅读:284      评论:0      收藏:0      [点我收藏+]

#查看表的结构

mysql> desc score;
+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(4)       | NO   | PRI | NULL    | auto_increment |
| name       | char(20)     | NO   |     | NULL    |                |
| score      | double(16,2) | YES  |     | NULL    |                |
| evaluation | char(20)     | YES  |     | normal  |                |
+------------+--------------+------+-----+---------+----------------+
4 rows in set (0.00 sec)

 

 

#alter对字段操作

#添加字段

mysql> alter table exam_score add other int(4) default 10;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

#修改字段变为另一个字段

mysql> alter table exam_score change other evaluation char(20) default normal; 
Query OK, 4 rows affected (0.02 sec)
Records: 4  Duplicates: 0  Warnings: 0

#删除字段(即删除字段中的所有数据)

mysql> alter table exam_score drop column other;
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

 

#修改表名

mysql> rename table exam_score to score;
Query OK, 0 rows affected (0.01 sec)

 

程序媛计划——mysql修改表结构

原文:http://www.cnblogs.com/IcarusYu/p/7497289.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!