Reputation: 377
I Wrote this code:
CREATE TRIGGER testT BEFORE INSERT ON test3
FOR EACH ROW
IF NEW.a> NEW.b
THEN NEW.a=0
in mysql and table test3(a,b)
what i want is if user inserted a and b in test3 and a>b then a becomes 0 how should i write this?cause currently this code isnt working and im getting MySQL said:
.#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 '.a=0' at line 2
Upvotes: 0
Views: 35
Reputation: 12105
That is not the valid syntax for a trigger, you forgot to use SET
. Try this:
CREATE TRIGGER testT
BEFORE INSERT ON test3
FOR EACH ROW
IF NEW.a> NEW.b
THEN SET NEW.a=0;
END IF;
Upvotes: 2