我正在尝试使用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
任何语法错误或结构问题?请帮忙
答案 0 :(得分:1)
在MySQL中,您无法更新子查询。代替:
update my_network_ref
set active = 0
where id = old.rid
limit 1;
通常情况下,使用order by
时会使用limit
。