我必须在我的桌子上写一个触发器,它将执行以下功能。
- 在行更新之前,检查项目的价格
- 如果价格与上次价格相比发生了变化,则从另一个具有项目类型和相关表名的表中选择表名、插入项目名的位置。
- 在选定的表中插入项目名称。
简单地说,我有一个表(TypeNameTable),其中包含项目类别和相应的表名,如果项目的价格发生了变化,那么我必须从TypeNameTable获取表名并将项目名插入到表中,该表被检索来自TypeNameTable。当我动态获取表名时,我无法插入到表中。请建议如何做。这就是我正在做的事情:
BEGIN
#declare countryTableName varchar(50);
declare itemPrice int;
declare itemTableName text;
IF (New.Price != Old.Price) THEN
SET countryTableName = (select `ItemManager`.`TypeNames`.`TypeTableName`
from `ItemManager`.`TypeNames`
where `ItemManager`.`TypeNames`.`ItemType` = NEW.ItemType);
INSERT INTO `ItemManager`.itemTableName
( `ItemName`, `ItemPrice`,
VALUES
( NEW.Name, New.Price );
END IF;
END$$
我得到错误
ItemManager
.itemTableName 不存在。