I want the field current_price in table stock to be updated when we insert new into table stock_changes.
So stock.current_price should be updated to stock_changes.current_price
I have tried with triggers but it wont work.
CREATE TRIGGER update_stock
AFTER INSERT ON stock_changes
FOR EACH ROW
UPDATE stock
SET current_price =NEW.current_price
WHERE id = NEW.stock_id;
You need to use DELIMITER
.
Try this :
DELIMITER $$
CREATE TRIGGER update_stock
AFTER INSERT ON stock_changes
FOR EACH ROW
begin
UPDATE stock
SET current_price =NEW.current_price
WHERE id = NEW.stock_id;
end;
$$
DELIMITER ;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.