创建触发器(trigger)
创建触发器
DROP TRIGGER IF EXISTS `ins_table_name`;
DELIMITER ;;
CREATE TRIGGER `ins_table_name` AFTER INSERT ON `table_name` FOR EACH ROW begin
insert into table_name_record select *, 'insert', 0 from table_name where id = new.id;
end
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `upd_table_name`;
DELIMITER ;;
CREATE TRIGGER `upd_table_name` AFTER UPDATE ON `table_name` FOR EACH ROW begin
insert into table_name_record select *, 'update', 0 from table_name where id = new.id;
end
;;
DELIMITER ;
DROP TRIGGER IF EXISTS `del_table_name`;
DELIMITER ;;
CREATE TRIGGER `del_table_name` BEFORE DELETE ON `table_name` FOR EACH ROW begin
insert into table_name_record select *, 'delete', 0 from table_name where id = old.id;
end
;;
·