0

更新手順を書きたい

どの方法が最適か

1)方法 1

if(condition)="P"

update table 
set fields1
 where field2 = "2" ;


else(condition)="U"
update table
 set fields1
 where field3 = "3" ;

2) 方法 2

 case condition
   when "p"
update table 
set fields1
 where field2 = "2" ;


   when "u"
   update table
 set fields1
 where field3 = "3" ;

どの方法を使用する必要があるか、それを使用する理由と、他の方法が適していない理由を教えてください。

4

2 に答える 2

2
update table t
  set ...
  where (condition='P' and field2='2') or (condition='U' and field3='3')
于 2012-05-10T08:43:44.433 に答える
0

CASEはIFと比較してより効率的で読みやすいため、CASEを使用することをお勧めします。しかし、テーブルが小さく、チェックするケースが2つしかない場合..意味がないと思います..

于 2012-05-14T07:46:16.017 に答える