I want prevent update of two columns in a database row mysql by triggers, for ex my table is mymy
and they two columns are column1
and column2
and row id is 11
. How run it in mysql triggers?
I tried it as:
CREATE TRIGGER 'no_update' BEFORE INSERT ON 'mymy'
FOR EACH ROW BEFORE UPDATE , then check if NEW.column1 != OLD.column1 OR NEW.column2 != OLD.column2
and i have error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEFORE UPDATE , then check if NEW.id_relation != OLD.id_relation OR NEW.active !' at line 1
How can fix it?
If you really don't want to ever update the values of column1 and column2 then you can use the trigger to set the new values to the old ones, thus never updating them - I believe this to be what you're looking for.
CREATE TRIGGER test_trigger BEFORE UPDATE ON mymy
FOR EACH ROW BEGIN
SET NEW.column1 = OLD.column1, NEW.column2 = OLD.column2
END
you have a syntax error on the create trigger statement try to check the syntax of your query from this link http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html