1.在Oracle中可以用下面兩種:
01:
create table newtable as select * from oldtable;//用于復制前未創建新表newtable不存在的情況
02:
insert into newtable select * from oldtable;//已經創建了新表newtable 的情況
注意:第一種方式只是復制了表結構,但是主鍵什么的并沒有復制進去,所以用的時候要小心在意。
2.如果想簡單快速的復制表結構,而不需要oldtable里面的數據,可以用下面的語句:
create table newtable as select * from oldtable where 1=2;(把數據過濾掉)
3.如過newtable 和oldtable的表結構不同,可以使用下面的方式:
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中的數據添加到newtable中。可以這樣:
create table newtable as (select * from oldtable where ...);//加where過濾條件
6.最常見的情況是id列新表中要用,并且和舊表中的不同,使用下面的語句就可以了(我們可以重新建一個sequence)
create table yang(id,name) as select hibernate_sequence.nextval,t.ename from emp t;
7.要注意,導出表的時候不能用select...into語句。