符合条件的记录有则修改没有则添加的小优化技巧

通常的写法:

if(select count(1) from table where id=XXX)=0

  insert into XXX

else

  update table set xxx where id=XXX

优化后的写法:

update table set xxx where id=XXX

if @@rowcount=0 

  insert into XXX

第一种情况,无论如何都会执行两次操作,第二种情况只会运行一次操作!!

posted @ 2016-02-06 16:20  davidhou  阅读(166)  评论(0编辑  收藏  举报