如何优化这个sql

时间:2015-01-30 04:49:29

标签: mysql sql optimization triggers

这是触发器

create trigger tg1
after insert on table1
for each row
begin
update table2 set amount=if(isnull(amount),0,amount)+1 where t2_id=new.t1_id;
end;

如何优化:amount=if(isnull(amount),0,amount)+1

感谢

1 个答案:

答案 0 :(得分:2)

相当清洁:

amount=IFNULL(amount,0)+1