oracle复制一张表的数据到另一张表方法

复制到新表

create table 新表名称  as select * from 源表名称;

如将 test1中的数据复制到新表 test2中,可执行如下命令:

create table test2  as select * from test1;

如果只需要备份表结构,可执行如下命令:

create table test2  as select * from test1 where 1=0;

复制到已存在表

insert into 目标表 select * from 源表;

如将 test3中的数据复制到已存在表 test2中,可执行如下命令:

insert into test2 select * from test3;

扩展内容

同一张表中,将A字段的值赋给B字段

update table_name set B =  A;

将一张表的字段数据插入到另一张表的字段数据中

insert into 目标表(目标表字段1,目标表字段2,......)  select 源表字段1,源表字段2...... from  源表;

如将test1 name 和 age 字段的值插入test2 name 和 age 字段,可执行如下命令:

insert into test2(name,age) select name,age from test1;

将多张表的多个字段插入同一张表的多个字段

insert into 目标表(目标表字段1,目标表字段2,......)  select 源表1字段1,源表1字段2......,源表2字段1,源表2字段2...... from  源表1,源表2;

如将test1表的name和age字段,test2表的city和school字段写入test3表,可执行如下命令:

insert into test3(name,age,city,school) select a.name,a.age,b.city,b.school from test1 a,test2 b;

SQL Server 备份单张表语句如下:
SELECT * into 目标表 FROM 源表;

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值