gpt4 book ai didi

mysql - 错误 1288 : The target table is not updatable in MySQL trigger

转载 作者:行者123 更新时间:2023-11-29 10:29:24 29 4
gpt4 key购买 nike

我正在尝试在 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 中,您无法更新子查询。相反:

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

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

关于mysql - 错误 1288 : The target table is not updatable in MySQL trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47695149/

29 4 0