MySQL - Trigger for updating same table after insert

前端 未结 6 1735
长情又很酷
长情又很酷 2020-11-22 15:39

Here\'s what I\'m trying to do:

When there\'s a new INSERT into the table ACCOUNTS, I need to update the row in ACCOUNTS where

6条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 16:17

    This is how I update a row in the same table on insert

    activationCode and email are rows in the table USER. On insert I don't specify a value for activationCode, it will be created on the fly by MySQL.

    Change username with your MySQL username and db_name with your db name.

    CREATE DEFINER=`username`@`localhost` 
           TRIGGER `db_name`.`user_BEFORE_INSERT` 
           BEFORE INSERT ON `user` 
           FOR EACH ROW
             BEGIN
                SET new.activationCode = MD5(new.email);
             END
    

提交回复
热议问题