可能重复:
MySQL Trigger to prevent INSERT under certain conditions
在MySQL BEFORE INSERT TRIGGER
中如何在条件下跳过数据插入?
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 ;
答案 0 :(得分:4)
两种解决方案都会引发错误:
CALL non_existent_proc()
示例1:
...
IF @found THEN
CALL non_existent_proc();
END IF;
...
示例2:
...
IF @found THEN
SIGNAL SQLSTATE '02000' SET MESSAGE_TEXT = 'Wrong data';`
END IF;
...