MySQL disable all triggers

一笑奈何 提交于 2019-11-27 14:36:58

You can't disable triggers directly and I wouldn't recommend doing what you're suggesting but you could have your trigger check if a variable (in my example below @disable_triggers) is NULL before executing the trigger's content. For example:

Query:

SET @disable_triggers = 1;
// Your update statement goes here.
SET @disable_triggers = NULL;

Triggers:

IF @disable_triggers IS NULL THEN
    // Do something use as the trigger isn't disabled.
END IF;

It is not possible to 'disable' triggers in mysql, however a trick that can be used to get around this

Add a condition in your triggers like:

if (DISABLE_TRIGER <> 1 ) then 
#trigger body 
end if; 

and than if you want to disable triggers on import just:

SET @DISABLE_TRIGER = 1;

do imports

SET @DISABLE_TRIGER = 0;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!