【问题标题】:ERROR 1288: The target table is not updatable in MySQL triggerERROR 1288:目标表在 MySQL 触发器中不可更新
【发布时间】:2017-12-07 12:26:21
【问题描述】:

我正在尝试在 Mysql 中使用以下查询运行一个小触发器:

create trigger sample_trigger after delete on my_network
  for each row
  begin
      update (select active from my_network_ref where id=old.rid limit 1) vnetr set vnetr.active=0;
  end;

在 MySQL Workbench 中运行这些触发器后,我会收到以下错误

Operation failed: There was an error while applying the SQL script to the database.
ERROR 1288: The target table vnetr of the UPDATE is not updatable
SQL Statement:
CREATE DEFINER = CURRENT_USER TRIGGER `mam_db`.`sample_trigger ` AFTER DELETE ON `my_network` FOR EACH ROW
BEGIN
 update (select active from my_network_ref where id=old.rid limit 1) vnetr set vnetr.active=0;
END

任何语法错误或结构问题?请帮忙

【问题讨论】:

    标签: mysql sql database triggers


    【解决方案1】:

    在 MySQL 中,您不能更新子查询。而是:

    update my_network_ref
        set active = 0
    where id = old.rid
    limit 1;
    

    通常,您在使用limit 时会使用order by

    【讨论】:

    • 我如何使用 order by ?你能推荐一些关于这个查询的例子吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2011-09-24
    • 2012-03-13
    • 1970-01-01
    • 2015-01-17
    • 1970-01-01
    相关资源
    最近更新 更多