`

表的维护和改造

 
阅读更多

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;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics