Reputation: 1878
So, I have a MySQL table costumer with some fields
table <Customers>
ID Name Description State
0 Jack waiting 0
1 Jane complete 1
I want to write a trigger, which updates the State field It needs to set the value of State to 1, if the Description is updated and gets the value complete
So far, I've come up with this:
delimiter $$
CREATE TRIGGER customerUpdated
BEFORE UPDATE ON Customers
FOR EACH ROW
BEGIN
IF NEW.Description = 'completed' THEN
UPDATE Customers SET State = '1' WHERE id = OLD.id;
END IF;
END$$
delimiter ;
But I get the error:
Any help appreciated!
Upvotes: 1
Views: 198
Reputation: 62831
I think you just need to set NEW.State instead of running an UPDATE statement at all:
IF NEW.Description = 'completed' THEN
SET NEW.State = 1;
END IF
Upvotes: 1