Atitit 常见触发器功能总结
目录
1.1. mysql触发器实例 插入数据前更改数据值.mhtml 1
CREATE TRIGGER `insertChgDowntime` BEFORE INSERT ON `c_question_repository` FOR EACH ROW if new.download_times<100 then
SET NEW.download_times = 125;
end if;
CREATE TRIGGER `upAftChgDowntime` BEFORE UPDATE ON `c_question_repository` FOR EACH ROW if new.download_times<100 then
SET new.download_times = 139;
end if;
CREATE TRIGGER `title_cant_empty_trigger` BEFORE INSERT ON `fav` FOR EACH ROW if new.tar_title='' then
call throw('cantBeEmptyEx');
end if;
CREATE DEFINER=`root`@`localhost` PROCEDURE `throw`(`ex` varchar(255))
BEGIN
#SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT='手动抛出异常' ;
SIGNAL SQLSTATE 'HY000' SET MESSAGE_TEXT = ex ;
#select '';
END
Atitit MySQL 触发器指南 attilax
触发器的测试,要用sql语句麻烦些,可以作为sp来包含,这样测试方便