Oracle快速把表数据抽到新表,试题-Oracle 如何把一个表中的数据插入到另外一个表中? - 拿OFFER...

1.可以用下面两种:

1):

create table newtable as select * from oldtable;//用于复制前未创建新表newtable不存在的情况

2):

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语句。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值