Error creating Trigger
Hi,
I have below trigger which needs to UPDATE a database based on the current INSERTED but I am getting this error:
18:57:05 CREATE TRIGGER trigger_monitor AFTER INSERT ON monitor FOR EACH ROW BEGIN UPDATE hosts SET average_time = (SELECT AVG(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id), SET maximum_time = (SELECT MAX(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id), SET minimum_time = (SELECT MIN(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id) WHERE host_id = NEW.host_id Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET maximum_time = (SELECT MAX(roundtrip_time) FROM monitor WHERE host_id = NEW.' at line 7 0.000 sec
here is the code:
USE maxmon;
CREATE TRIGGER trigger_monitor
AFTER INSERT
ON monitor FOR EACH ROW
BEGIN
UPDATE hosts
SET average_time = (SELECT AVG(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id),
SET maximum_time = (SELECT MAX(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id),
SET minimum_time = (SELECT MIN(roundtrip_time) FROM monitor WHERE host_id = NEW.host_id)
WHERE host_id = NEW.host_id;
END
Subject
Views
Written By
Posted
Error creating Trigger
1921
July 24, 2019 08:57AM
696
July 24, 2019 04:21PM
748
July 25, 2019 12:12PM
650
July 25, 2019 12:15PM
658
July 25, 2019 12:26PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.