Update statement to update multiple rows

后端 未结 4 1316
盖世英雄少女心
盖世英雄少女心 2021-01-30 13:38

I have a question regarding the following syntax. Is there a cleaner way to roll this up into one statement rather than two. I\'ve tried several iterations but this seems to b

4条回答
  •  迷失自我
    2021-01-30 14:06

    I am looking for a less newbie way

    Doing two separate update statements is (according to me) "the less newbie way" you could complicate stuff and do something like this.

    update employee
    set hire_date = case emp_id
                      when 'PMA42628M' then '1979-03-15'
                      when 'PSA89086M' then '1988-12-22'
                    end
    where emp_id in ('PMA42628M', 'PSA89086M')
    

    but what would that gain you? The entire update would run in one implicit transaction so if you want your two updates to be in a transaction you just use begin transaction .... commit.

提交回复
热议问题