mysql与postgresql的表复制语句

在mysql中复制已有的表结构给一个新表的方法:

第一种方法:

create table custNew1 like customers;

这种方法只能被复制的表是什么结构,新表就是什么结构,无法在建表的同时进行增加新列的行为。不过新表会保留被复制表的索引结构。

 

第二种方法:

create table custNew2(id int auto_increment not null primary keyselect * from customers;

这种方法是可以新添加列的,不过它不会保留被复制表的索引结构。上面这条语句不仅会把被复制表的结构复制过来,数据也会被复制。如果不想复制数据可以加'where'子句:

create table custNew2(id int auto_increment not null primary keyselect * from customers where 1<>1;

 

在postgreSQL中复制已有的表结构方法:

select * into custNew from customers where 1<>1;

上面这句是只复制表结构,如果想要数据一起过来,把where子句删除即可。它提索引也是不保留的。

 


 

 

posted @ 2011-05-29 17:56  番茄侠  阅读(3698)  评论(0编辑  收藏  举报