mysql - Trigger with two IF blocks -
hello have problem trigger when use alone works no. how can fix syntax error?
create trigger `c_edit` after update on `client` each row if old.name != new.name insert `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) values (old.id_user_edit, 'client', 'name', old.id_client, '4', old.name, new.name); end if; if old.name_sql != new.name_sql insert `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) values (old.id_user_edit, 'client', 'name_sql', old.id_client, '4', old.name_sql, new.name_sql); end if; error: #1064 - have error in sql syntax; check manual corresponds mysql server version right syntax use near '' @ line 4
since using multiple statements within trigger's body, need use mysql's begin ... end compound statement syntax, along delimiter
statement change delimiter:
delimiter // create trigger `c_edit` after update on `client` each row begin if old.name != new.name insert `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) values (old.id_user_edit, 'client', 'name', old.id_client, '4', old.name, new.name); end if; if old.name_sql != new.name_sql insert `change`(`id_user`, `table`, `column`, `id`, `status`, `before`, `now`) values (old.id_user_edit, 'client', 'name_sql', old.id_client, '4', old.name_sql, new.name_sql); end if; end// delimiter ;
Comments
Post a Comment