码迷,mamicode.com
首页 > 其他好文 > 详细

ZAQI

时间:2019-10-28 14:57:17      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:end   stat   div   efault   innodb   enum   new   last   aqi   

mysql> CREATE TABLE emploee (
    -> name CHAR(64) NOT NULL,
    -> email CHAR(64),
    -> password CHAR(64),
    -> PRIMARY KEY (email)
    -> ) ENGINE = InnoDB;
Query OK, 0 rows affected (0.01 sec)


mysql> CREATE TABLE log ( id INT AUTO_INCREMENT, email CHAR(64), message TEXT,
    -> status ENUM(‘FAIL‘,‘OK‘)DEFAULT ‘FAIL‘,
    -> ts TIMESTAMP,
    -> PRIMARY KEY(id)
    -> )ENGINE=MyISAM;
Query OK, 0 rows affected (0.00 sec)

    -> delimiter $$
    -> CREATE TRIGGER tr_employee_insert_before BEFORE INSERT ON emploee
    -> FOR EACH ROW
    -> BEGIN
    -> INSERT INTO log(email,message)
    -> VALUES (NEW.email,CONCAT(‘Adding employee‘,NEW.name));
    -> SET @LAST_INSERT_ID = LAST_INSERT_ID();
    -> END $$

mysql> CREATE TRIGGER tr_employee_insert_after AFTER INSERT ON emploee
    -> FOR EACH ROW
    -> UPDATE log SET status = ‘OK‘ WHERE id = @LAST_INSERT_ID;

  

ZAQI

标签:end   stat   div   efault   innodb   enum   new   last   aqi   

原文地址:https://www.cnblogs.com/betterquan/p/11751602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!