Sunday, 15 February 2015

sql - MySQL BEFORE UPDATE trigger - change value -



sql - MySQL BEFORE UPDATE trigger - change value -

so, i've got mysql table, named employees.

id name meta 0 jack ok 1 anne del

i want write trigger prevents row meta='del' update meta field. so, if do:

update employees set meta = 'busy' id = 0

the row should updated , meta 'busy'

but when do:

update employees set meta = 'busy' id = 1

the meta field should still 'del'

i tried:

delimiter $$ create trigger updateemployees before update on employees each row begin if old.meta = 'del' new.meta = 'del' end if; end$$ delimiter ;

but mysql returns syntax error. ideas?

you forgot add together set clause. way doesn't alter value.

delimiter $$ create trigger updateemployees before update on employees each row begin if old.meta = 'del' set new.meta = 'del'; end if; end$$ delimiter ;

mysql sql triggers

No comments:

Post a Comment