表的维护和改造

1.alter table 命令来修改表的列构造的。

(1)修改列的定义:alter table... modify
alter table customer modify name vachar(20);
改变列的位置:alter table customer modify age int after name;
(2)追加列: alter table... add
alter table customer add age int;
在任意位置加:alter table customer add age int agter name; 
(3)修改列的名称与定义: alter table... change
alter table customer change birth birthday date;
(4)删除列: alter table... drop
alter table customer drop age;
2.复制表和删除表
表的列构造+数据的复制
表的列构造的复制
数据的复制
(1).表的列构造与数据的复制
create table customerH select * from customer;
注意:使用此方法复制可能发生列属性被改的情况,比如:mysql的版本,varchar(20)变成char(20)。另外,可能发生不能复制index 的有关设定情况。复制完成后可以用desc命令来确认下表的构造。
(2).复制表的构造
create table customerG like customer;
(3)数据的复制
复制数据:insert into customerG select * from customer;
复制某一列的数据(将customer name列复制到userName列中,customerG其他列将为NULL):insert into customerG(userName) select name from customer; 
(4)表的删除
drop table customerG;
先检查表是否存在在删除: drop table if exists customerG;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值