1.在Oracle中可以用下面兩種:
01:
create table newtable as select * from oldtable;//用于復(fù)制前未創(chuàng)建新表newtable不存在的情況
02:
insert into newtable select * from oldtable;//已經(jīng)創(chuàng)建了新表newtable 的情況
注意:第一種方式只是復(fù)制了表結(jié)構(gòu),但是主鍵什么的并沒(méi)有復(fù)制進(jìn)去,所以用的時(shí)候要小心在意。
2.如果想簡(jiǎn)單快速的復(fù)制表結(jié)構(gòu),而不需要oldtable里面的數(shù)據(jù),可以用下面的語(yǔ)句:
create table newtable as select * from oldtable where 1=2;(把數(shù)據(jù)過(guò)濾掉)
3.如過(guò)newtable 和oldtable的表結(jié)構(gòu)不同,可以使用下面的方式:
create table newtable as select s.c1,s.c2 from oldtable s;
4.如果想重新命名newtable的列名:
在oracle中:
create table newtable(id,name1) as select s.c1,s.c2 from oldtable s;
或者
create table newtable as select s.c1 ,s.c2 from oldtable s;
在mysql中恐怕只能用第二種方式了。
5.如果是只需要把一部分的oldtable中的數(shù)據(jù)添加到newtable中。可以這樣:
create table newtable as (select * from oldtable where ...);//加where過(guò)濾條件
6.最常見(jiàn)的情況是id列新表中要用,并且和舊表中的不同,使用下面的語(yǔ)句就可以了(我們可以重新建一個(gè)sequence)
create table yang(id,name) as select hibernate_sequence.nextval,t.ename from emp t;
7.要注意,導(dǎo)出表的時(shí)候不能用select...into語(yǔ)句。