MySQL Triggers: table to table
I need to write a trigger that will create a record in another table.
In my user table when a registering user responds to an activation email their status in that table changes from 0 to 1. When this change occurs I need it create a record in another table that has an auto-incrementing int primary id (Party).
Since the user status can be of three different states (not active (0), active (1), and banned (-1) I need this trigger to only set off when the status is changed from 0 to 1.
Can someone please help m开发者_运维问答e with the SQL here?
DELIMITER $$
CREATE TRIGGER users_status_change AFTER UPDATE on users
FOR EACH ROW BEGIN
IF OLD.Status = 0 AND NEW.Status = 1 THEN
INSERT Party(Name)
VALUES('blar blar');
END IF;
END;
$$
DELIMITER ;
精彩评论