MySQL 触发器

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;
posted on 2018-09-30 17:51  降魔  阅读(81)  评论(0编辑  收藏  举报