多表批量(关联)更新 oracle、mysql和sqlserver

[b]多表批量(关联)更新 [/b]
把表A中的name1字段设为对应的B表中的name1字段

[b]1.oracle[/b]
update test1 a set name=(select name from test2 b where a.no=b.no) where exists(select name from test2 b where a.no=b.no); --防止插入null值
update test1 a set name=(select name from test2 b where a.no=b.no)

根据已有表创建新的表
CREATE TABLE TAB_NEW (PARTITION ....) AS SELECT * FROM TAB_OLD的方式(考虑并行和NOLOGGING)
create table asm_op_log_1 as select * from asm_op_log t; (复制表不存在)
insert into asm_op_log_2 select * from asm_op_log t; (复制表已经存在)
[b]2.mysql [/b]
update table1 a ,table2 b set a.tValue =b.tValue where a.id=b.id

[b]3.sqlserver [/b]
update a set a.name1 = b.name1, a.name2=b.name2 from 表A a, 表B b where a.id=b.id

insert into asm_op_log_2 select * from asm_op_log t;(复制表已经存在)
select 字段列表 into 复制表名称 from 表 (复制表不存在)


--------------------------------分割线------------------------------------------


插入指定字段的案例:
insert into wx_rc_contacts(id,name,sex,dept,roles,mobile,email)
(select wx_rc_contacts_seq.NEXTVAL,name,sex,dept,roles,mobile,email from wx_rc_contacts2 t
where t.name not in(select name from wx_rc_contacts));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值