数据库操作的一些命令

full join

左右全查,没关联的用null填入

mysql 没有此功能,如下方法可以达到同样效果:

select * from `profile` as p left join news as n on p.`id` = n.`profile_id`

UNION

select * from `profile` as p right join news as n on p.`id` = n.`profile_id`


UNION 是去掉重复的记录,如果表本身就重复,则不能用此方法。

复制表:


复制表的数据结构和数据


create table a select * from b;


复制表的其中几列


create table a select b.id,b.name from b;


复制带有条件的表


create table a select * from b where id > 3;


就复制表结构,不要数据


第一种方法:create table a select * from b where 0=1;


第二种方法:create table a like b;


第三种方法:先show create table b;获得建表的sql语句,再想办法建表


复制旧表结构,增加自己的新字段


create table a(status varchar(10)) select * from b where 0=1;

mysql修改表:

增加字段:


alter table a add age int not null;


修改字段:


修改字段名和类型:


alter table a change name name11 varchar(10) not null;

如果由varchar型改为int型,则此列数据全部为0


修改字段类型:


alter table a modify name11 int not null;


删除字段:


alter table a drop id;


改变表名:


alter table c1 rename c2;

改变表类型:


alter table c1 type=myisam

更多详情参见:http://wenku.baidu.com/view/3d4201283169a4517723a325.html

猜你喜欢

转载自gerrard-ok.iteye.com/blog/1340447