oracle学习 复制表结构和表数据

来源:互联网 发布:ps如何做淘宝详情页 编辑:程序博客网 时间:2024/06/08 23:34
面试中遇到的问题,搜集整理一下:

在oracle中复制表结构和表数据:

1、复制表结构及数据:

create table new_table as select * from old_table

2、只复制表结构:

create table new_table as select * from old_table where 1<>1

3、复制表的指定字段:

create table new_table as select column1,column2... from old_table where 1<>1 (前提是column1...是old_table的列)

4、复制表的指定字段及数据:
  
create table new_table as select column1,column2... from old_table where(前提是column1...是old_table的列)

5、在已存在的表中插入数据:

A.两个表结构一样

insert into new_table select * from old_table (前提是必须要有一个new_table 表才能查数据)

B.表结构不一样:

insert into new_table (column1,column2...) select column1,column2... from old_table (注意:两个表中的要复制的列数据类型和长度最好要一致,要注意长度大小问题)


以上语句能根据已有的表来创建新表及数据,但是已有表的索引却复制不了,需要在新表中手动建立,而且注释什么的都不会被复制过来的。


0 0
原创粉丝点击