`
gerrard_ok
  • 浏览: 143199 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

数据库操作的一些命令

 
阅读更多

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

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics