开发者

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?

MySQL Triggers: table to table


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 ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜