我在phpMyAdmin工作,我是创建MySQL 5.0.45触发器的新手。我正在尝试创建一个触发器,通过在值超出范围时抛出错误来帮助我验证数据。
这很好用:
create trigger t1
before insert
on hvi
for each row
begin
declare dummy int;
if new.`Moist (dry%)` <1 then
select `Moist(dry%) cannot be less than 1`
into dummy
from hvi
where id = new.`Moist (dry%)`;
end if;
end;
但我需要为此触发器添加更多操作。我厌倦了这个:
create trigger t1
before insert
on hvi
for each row
begin
declare dummy int;
if new.`Moist (dry%)` <1 then
select `Moist(dry%) cannot be less than 1`
into dummy
from hvi
where id = new.`Moist (dry%)`;
end if;
if new.`Moist (dry%)` >50 then
select `Moist(dry%) cannot be greater than 50`
into dummy
from hvi
where id = new.`Moist (dry%)`;
end if;
end;
但是它返回了这个错误“#1235 - 这个版本的MySQL还不支持'多个触发器,一个表具有相同的动作时间和事件'”
有谁知道如何向触发器添加多个动作? (多个if-then语句?我最终需要添加大约20个。)
谢谢!
答案 0 :(得分:2)
您需要在创建新触发器之前删除现有触发器:
DROP TRIGGER IF EXISTS t1;
CREATE TRIGGER t1
...