【发布时间】:2021-09-29 02:51:59
【问题描述】:
我正在尝试更新 product_stock 表中的 Product 项目数量(当 Product 表中发生 UPDATE 时,它将更新 product_stock 表中的 Product 数量)。但是错误正在运行 -> 错误代码:1054。'where 子句'中的未知列'product.id_product'
CREATE TABLE IF NOT EXISTS `product`(
`id_product`INT(11) NOT NULL AUTO_INCREMENT,
`unitarya_value`DECIMAL NOT NULL,
`minimum_quantity` INT(11) NOT NULL,
PRIMARY KEY(`id_product`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
CREATE TABLE IF NOT EXISTS `stock_product`(
`id_stock_product`INT(11) NOT NULL AUTO_INCREMENT,
`current_quantity`INT(11) NOT NULL,
`id_product`INT(11) NOT NULL,
PRIMARY KEY(`id_stock_product`),
FOREIGN KEY(`id_product`)
REFERENCES `product` (`id_product`)
ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
DELIMITER $$
CREATE TRIGGER updateProductquantity
BEFORE UPDATE ON product
FOR EACH ROW
BEGIN
DECLARE qtt INT DEFAULT 50;
UPDATE stock_product set current_quantity = current_quantity + qtt
WHERE stock_product.id_product = product.id_product ;
END; $$
【问题讨论】: