MySQL`BEFORE INSERT TRIGGER`如何在条件下跳过数据插入? [英] MySQL `BEFORE INSERT TRIGGER` how can I skip data insertion under condition?
本文介绍了MySQL`BEFORE INSERT TRIGGER`如何在条件下跳过数据插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
MySQL触发器在某些条件下阻止INSERT
在MySQL BEFORE INSERT TRIGGER
如何在条件下跳过数据插入?
In MySQL BEFORE INSERT TRIGGER
how can I skip data insertion under condition?
delimiter //
drop trigger if exists test_trigger //
create trigger test_trigger before insert on t
for each row
begin
set @found := false;
#Some code
if @found then
#How to skip the data insertion under condition?
end if;
end //
delimiter ;
推荐答案
两个解决方案都会引发错误:
Two solutions, both raise an error:
- 调用不存在的存储过程 -
CALL non_existent_proc()
- 使用 SIGNAL 语句引发错误(MySQL 5.5)。
- Call non-existent stored procedure -
CALL non_existent_proc()
- Use SIGNAL statement to raise the error (MySQL 5.5).
示例1:
...
IF @found THEN
CALL non_existent_proc();
END IF;
...
示例2:
...
IF @found THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Wrong data';`
END IF;
...
这篇关于MySQL`BEFORE INSERT TRIGGER`如何在条件下跳过数据插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文