mysql支持设定session变量,并且有带入到触发器中使用的能力,故可以间接的设置触发器失效
思路是:
在执行前设定一个session变量,执行过程中判断该变量的值(没有设定该变量的值时该变量默认值为null)
例:
set @disable_triggers = 1;
UPDATE
std_importpc pc JOIN std_import_checked chk on pc.TrademarketCode in ('0','1') and chk.Texch = '.OF'
and chk.SecuCode = pc.SecuCode
set pc.checkedID = chk.ID;
set @disable_triggers = NULL;
ALTER TABLE `std_importchoice` AUTO_INCREMENT=6854278;
DROP TRIGGER IF EXISTS `TRG_PC_Checked`;
DELIMITER ;;
CREATE TRIGGER `TRG_PC_Checked` AFTER UPDATE ON `std_importpc` FOR EACH ROW
begin
IF @disable_triggers IS NULL THEN
update std_import_checked d set d.Version = now() , d.CheckedStatus = 3 where d.SecuCode = new.SecuCode and d.TrademarketCode = new.TrademarketCode and d.CheckedStatus = 4;
End IF;
end
;;
DELIMITER ;
(责任编辑:好模板) |