MySQL 觸發器
阿新 • • 發佈:2018-09-30
mar trigger form signed begin set com engine cte 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=InnoDBDEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ciAUTO_INCREMENT=7ROW_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 觸發器