For test correctness of query I need disable all triggers in db. I see that in information_schema exists table TRIGGERS. Is possible temporarily disable all triggers using this table? E.g. like:
update TRIGGERS set TRIGGERS_SCHEMA='myschema_new'
where TRIGGERS_SCHEMA='myschema'
and after finish all test return all triggers like:
update TRIGGERS set TRIGGERS_SCHEMA='myschema'
where TRIGGERS_SCHEMA='myschema_new'
May be this can corrupt db or after triggers will not works? I didn't found about it in documentation.
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;
来源:https://stackoverflow.com/questions/6480074/mysql-disable-all-triggers