update a set b=case b when 'e2' then 'e4' else 'e2' end
where b in('e4','e2')

解决方案 »

  1.   

    --一次更新就行了begin tran
    update a set b=case b when 'e2' then 'e4' else 'e2' end
    where b in('e4','e2')
    commit tran
      

  2.   

    邹哥,我还是想了解一下在sql server里怎样实现延迟提交事务,因为有时候比较复杂,可能是
    把主键e1改e2,e2改e3,e3改e4,e4改e1
      

  3.   

    不具备这种能力,如果要实现那种复杂的修改的话,你可以用临时表来处理--将要处理的数据放入临时表,b是旧主键列,b1用来存放新主键列
    select b,b1=b into #t from a where b in('e4','e2')--修改b1列的值为新主键列的值
    update #t set b1='e2' where b='e4'
    update #t set b1='e4' where b='e2'--更新回原表
    update a set b=b.b1 from a,#t b where a.b=b.bdrop table #t