【问题标题】:How to create a trigger with multiple actions in MySQL 5.0.45?如何在 MySQL 5.0.45 中创建具有多个操作的触发器?
【发布时间】:2011-04-03 21:29:45
【问题描述】:

我在 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 个。)

谢谢!

【问题讨论】:

    标签: mysql sql triggers mysql-error-1235


    【解决方案1】:

    您需要先删除现有触发器,然后再创建新触发器:

    DROP TRIGGER IF EXISTS t1;
    CREATE TRIGGER t1
    ...
    

    【讨论】:

    • 艾克在这里是正确的。我不小心在这张桌子上有另一个触发器。一旦我删除它。 . .我可以在这里毫无问题地创建我的 t1。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    • 2014-12-18
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多