大家好,我打算为 MySQL 表创建一个触发器,以便在将值插入到表中后,列 exp_sales
设置为 qnty_received
值 * sell_price 但我我收到此错误:
ERROR 1193 (HY000): Unknown system variable 'exp_sales'
这是我的查询:
delimiter $$
Create trigger tsales after insert on Store_info_table
for each row
set exp_sales = qnty_received * selling_price;
END$$
问题是什么?创建触发器的最佳方法是什么,以便在插入数量和销售价格后,exp_sales(Total)
字段更新为正确的值?
最佳答案
如果我理解正确的话,exp_sales
是您要更新的列名称:
delimiter $$
Create trigger tsales after insert on Store_info_table
for each row
update Store_info_table
set exp_sales = NEW.qnty_received * NEW.selling_price
where id = NEW.id;
END$$
更好的方法是使用 INSERT INTO ON DUPLICATE KEY UPDATE
INSERT INTO table_name(...)VALUES(...)
ON DUPLICATE KEY SET exp_sales = qnty_received * selling_price;
关于mysql - 错误 1193 (HY000) : Unknown system variable while Creating a trigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12005879/