假设表B
有一个BEFORE DELETE
触发器。但是,在某些情况下,我希望当我尝试从 B
中删除某些内容时禁用触发器,这可能吗?
最佳答案
在触发器中插入条件验证(if),以检查执行操作的条件是否会被执行
例如:
create trigger ai_eav after insert on eav
for each row begin
set @id=new.entity;
set @attribute=new.attribute;
set @value=new.value;
if n > m then
update pivot set
Author=(select if(@attribute='Author',@value,Author)),
Title=(select if(@attribute='Title',@value,Title)),
Publisher=(select if(@attribute='Publisher',@value,Publisher))
where id=@id;
end if
end
你可以在这里找到 mysql if 语句的语法: http://dev.mysql.com/doc/refman/5.0/en/if.html
此解决方案可能比删除并重新创建触发器更具性能
关于mysql - MySQL 中可以暂时忽略触发器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23248351/