直接上代码
DROP TRIGGER IF EXISTS `trigger_book` ;
DELIMITER $$
CREATE DEFINER=`root`@`%` TRIGGER trigger_book after update ON book FOR EACH ROW
BEGIN
declare nowtime int(11);
set @b1 ='';
set nowtime=unix_timestamp(now());
if (old.cooperation!=new.cooperation or new.base!=old.base or new.buyout!=old.buyout or new.into!=old.into or new.quan!=old.quan) then
if (old.cooperation!=new.cooperation) then
set @b1=concat(" 修改签约类型为:",new.cooperation," 旧值:",old.cooperation);
end if;
if (new.base!=old.base) then
set @b1=concat(@b1," 修改保底为:",new.base," 旧值:",old.base);
end if;
if (new.buyout!=old.buyout) then
set @b1=concat(@b1," 修改买断为:",new.buyout," 旧值:",old.buyout);
end if;
if (new.quan!=old.quan) then
set @b1=concat(@b1," 修改全勤为:",new.quan," 旧值:",old.quan);
end if;
if (new.`into`!=old.`into`) then
set @b1=concat(@b1," 修改分成为:",new.`into`," 旧值:",old.`into`);
end if;
insert into opt_log(opt_uid,opt_value,opt_time,bid)value(new.opt_uid,@b1,nowtime,new.id);
end if;
end
$$#
DELIMITER ;
以上是修改书的签约类型时,记录对应的人以及对应的修改前后的值。
可能应用场景有限,但是这不需要在应用层去做相关功能, 直接数据库里就完事了。
评论 (0)