我在MySQL创建该触发器(上表产品更新后):SQL错误(1442),任何解决方案?
BEGIN
set @parentid := (select parent_id from product where product_id = new.product_id);
if (old.price <> new.price) then
update product set price=new.price where product_id = @parentid and price > new.price;
end if;
END
但是,当我更新的价格,我得到这个错误
:SQL错误(1442)无法更新表'产品'存储在 函数/触发器中,因为它已经被调用了 的存储函数/触发器使用。 */
我创建两个表和两个触发器等:
Trigger 1
(后上表产品更新):
BEGIN
if (old.price <> new.price) then
insert into product_price
(product_id, price , date_added)
values
(new.product_id, new.price, SYSDATE());
end if;
END
Trigger 2
(后上表product_price
插入):
BEGIN
SET @parentid := (select parent_id from product where product_id = new.product_id);
if (@parentid >0) then
update product set price=new.price where product_id in (select @parentid);
end if;
END
但是,我又得到了那个错误。
我真的需要在儿童价格变化时更新父母价格,你有什么解决方案吗?
谢谢。
你究竟想要做什么?在明确更新它之后,您希望product.price具有什么价值? – JRD
@JRD他没有对正在插入或更新的行进行任何更改,他正在尝试更新父级产品。 – Barmar
我有一些儿童产品,我需要显示父母产品上最便宜的儿童价格。 –