码迷,mamicode.com
首页 > 其他好文 > 详细

19_列的增删改

时间:2015-05-20 18:45:13      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:default   change   primary   null   


表的管理之列的增删改


1.增

  alter table 表名 add 列声明;

默认这个新增的列在表的最后一列。

如果不想要新增的列在表的最后一列,那么可以:

  alter table 表名 add 列声明 after 列名;

  alter table 表名 add 列声明 first;


2.删

  alter table 表名 drop 列名;



3.改

  alter table 表名 change 被改变的列名 列声明;



----------------------


1.默认在表的最后一行增加一列身高sg:

  alter table boy add sg tinyint not null default 111;


2.在列flower后增加一列age:

  alter table boy add age tinyint not null default 20 after flower;


3.在表的第一列前面新增一列id:

  alter table boy add id int primary key auto_increment first;


4.把身高列sg列名改成height ,属性改成无符号的tinyint unsigned:

  alter table boy change sg height tinyint unsigned;


5.把新增的列都删掉

  alter table boy drop height;

  alter table boy drop age;

  alter table boy drop id;


19_列的增删改

标签:default   change   primary   null   

原文地址:http://1154179272.blog.51cto.com/10217799/1653260

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!