Oracle-复制表结构,复制表数据
在oracle中复制表结构和表数据:
1、复制表结构及数据:
1 | create table new_table as select * from old_table; |
2、只复制表结构:
1 | create table new_table as select * from old_table where 1<>1; |
3、复制表的指定字段:
1 | create table new_table as select column1,column2… from old_table where 1<>1; |
4、复制表的指定字段及数据:
1 | create table new_table as select column1,column2… from old_table where <筛选条件> ; |
以上语句能根据已有的表来创建新表及数据,但是已有表的索引却复制不了,需要在新表中手动建立,而且注释什么的都不会被复制过来的。
5、从已存在的表中查询数据并插入到另外一张表:
A.两个表结构一样
1 | insert into new_table select * from old_table; |
B.表结构不一样:
1 | insert into new_table (column1,column2…) select column1,column2… from old_table; --(注意:两个表中的要复制的列数据类型和长度最好一致,要注意长度大小问题) |
------ 本文完 ------