update多列的几种选择

当update 多列 时有如下几种选择
1.)教科书式写法
update t_table a
    set f1=(select f1 from testz b where a.id=b.id),
           f2=(select f2 from testz b where a.id=b.id),
           f3=(select f3 from testz b where a.id=b.id)
    where id=2;

2.)教科书变种
update t_table a
    set (f1,f2,f3)=(select f1,f2,f3 from testz b where a.id=b.id)
    where id=2;
虽然道理和方法1一样,却省了不少事

3.)另类nest table写法
update (select f1,f2,f3 from t_table where id=2)
    set (f1,f2,f3)=(select f1,f2,f3 from testz b where id=2);
此方法虽然比2的代码 量要多一些,但是没有表连接,如果两个表都在id列有主键,速度应该较方法1和方法2快一些.

说明:update是一个耗回滚段,耗重做日志,耗时间,耗成本的操作,尤其是大表的多列update,如有必要应比较其与重新建表的效率

 

本人博客已搬家,新地址为:http://yidao620c.github.io/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值