码迷,mamicode.com
首页 > 数据库 > 详细

MySQL 触发器

时间:2018-09-30 20:00:39      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:name   com   _for   cte   ODB   log   int   host   concat   

CREATE TABLE `NewTable` (
`id`  int(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`name`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`pwd`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
PRIMARY KEY (`id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=7
ROW_FORMAT=COMPACT
;
CREATE DEFINER=`root`@`localhost` TRIGGER `add` AFTER INSERT ON `NewTable`
FOR EACH ROW BEGIN
    insert into ht_log (logtime,content) values (NOW(),CONCAT(‘添加用户‘,new.name));
END;
CREATE DEFINER=`root`@`localhost` TRIGGER `update` AFTER UPDATE ON `NewTable`
FOR EACH ROW BEGIN
    insert into ht_log (logtime,content) values (NOW(),CONCAT(‘修改用户‘,old.name,‘->‘,new.name,‘;‘,old.pwd,‘->‘,new.pwd));
END;
CREATE DEFINER=`root`@`localhost` TRIGGER `delete` AFTER DELETE ON `NewTable`
FOR EACH ROW BEGIN
    insert into ht_log (logtime,content) values (NOW(),CONCAT(‘删除用户‘,old.name));
END;

MySQL 触发器

标签:name   com   _for   cte   ODB   log   int   host   concat   

原文地址:https://www.cnblogs.com/fanhuo/p/9732893.html

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