错误1288:目标表在MySQL触发器中不可更新

时间:2017-12-07 12:26:22

标签: mysql sql database triggers

我正在尝试使用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

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

1 个答案:

答案 0 :(得分:1)

在MySQL中,您无法更新子查询。代替:

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

通常情况下,使用order by时会使用limit