我有触发如下面的例子:如何使用MySQL触发器“假”,“开关”命令
BEFORE UPDATE ON icharts_user_stats FOR EACH ROW BEGIN
IF (NEW.col1> OLD.col1
OR NEW.col2 > OLD.col2) THEN
SET NEW.col3 = NEW.col3+1;
SET NEW.col4 = NEW.col4+1; END IF;
IF (NEW.col5> OLD.col5
OR NEW.col6 > OLD.col6) THEN
SET NEW.col7 = NEW.col7+1; END IF;
IF (NEW.col8> OLD.col8
OR NEW.col9 > OLD.col9) THEN
SET NEW.col10 = NEW.col10+1; END IF;
这有点像switch语句,只在一个“如果”将被执行的任何点。上面的代码工作,但如果第一个“如果”被击中,它仍然会经历所有其他IFS。
- 有没有更好的办法做到这一点?
- 以“走”之前“结束,如果”是个好主意
感谢
或用[ELSEIF(http://dev.mysql.com/doc/refman/5.5/en/if-statement.html)类似:http://stackoverflow.com/questions/3056783/ – xQbert