mysql - Multiple If conditions in a trigger -


i want write multiple if conditions check values of different columns of same table in trigger. checking 2 columns right , getting mysql error

#1064(syntax error) @ line # 17. 

following conditions. plz me im doing wrong.

if (old.ce_en_option_id != new.ce_en_option_id) insert  audit_log( beneficiary_id , table_name , field_name , old_value , new_value , edit_by, date_time ) values ( old.beneficiary_id,  'be_ce_main',  'ce_en_option_id', old.ce_en_option_id, new.ce_en_option_id, new.edited_id,now() ); end if;  if(old.ce_dm_option_id != new.ce_dm_option_id) insert  audit_log( beneficiary_id , table_name , field_name , old_value , new_value , edit_by, date_time ) values ( old.beneficiary_id,  'be_ce_main',  'ce_dm_option_id', old.ce_dm_option_id, new.ce_dm_option_id, new.edited_id,now() ); end if; 

you missing begin - end block. , fear did not override delimiter instruct sql engine not execute statements ending default statement terminator ; semicolon. because didn't define new delimiter, sql engine assumed end of statement @ first found ; semicolon. there failed because statements not in proper syntax order.

try following:

delimiter //  create trigger 'test_trigger' after update on 'be_ce_main' each row begin -- must if have more 1 executable statements below  -- trigger body here  end; //  delimiter ; 

refer to:

mysql: create trigger syntax


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -