T-SQL和PL/SQL表关联更新语句的区别

SQLserver与Oralce中的两表关联更新是区别的。

在T-SQL中更新相对简单些,直接用下面的语句都是可以:

Update b
Set b.processflag = a.processflag
From temp_1 a Join temp_2 b
On a.msgid_db = b.msgid

Update temp_2
Set Usertime = b.Usertime
From temp_2 a Join temp_1 b
On a.msgid = b.msgid_db

Update temp_2
Set Usertime = b.Usertime
From temp_1 b
where msgid = b.msgid_db

而在Oracle中这样写是不对的,应该更改如下:

Update Temp_2 a
   Set a.Usertime = (Select b.Usertime
             From Temp_1 b
             Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);

更新多个字段:

Update Temp_2 a
   Set a.Usertime = (Select b.Usertime
             From Temp_1 b
             Where b.Msgid_Db = a.Msgid),
       a.processflag = (Select b.processflag
             From Temp_1 b
             Where b.Msgid_Db = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid);

多表关系更新:

Update Temp_2 a
   Set a.Usertime = (Select b.Usertime
             From Temp_1 b
             Where b.Msgid_Db = a.Msgid),
       a.processflag = (Select c.processflag
             From Temp_3 c
             Where c.Msgid = a.Msgid)
Where Exists (Select 1 From Temp_1 b Where b.Msgid_Db = a.Msgid)
        And Exists (Select 1 From Temp_3 c Where c.Msgid = a.Msgid);

感觉这点没sqlserver理简单易用~~~

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值