Alan Mulligan
Alan Mulligan

Reputation: 1198

SQL Trigger in phpmyadmin

I am looking to set up a trigger that will do some addition(the code below) on two columns if stage_1 or stage_2 is update.

Also is it possible to run the trigger ever 5 min instead of on every update. Thanks In advance for any help.

update monte_carlo_2013 set total = stage_1 + stage_2

I have had a look around the net at trigger and come up with this, which dose not work but am i going in the right direction

CREATE TRIGGER update_stage_1
ON monte_carlo_2013
AFTER INSERT
AS
BEGIN
update monte_carlo_2013 set total_after_1 = (stage_1 + penalty_after_1) WHERE car_num IN (SELECT car_num FROM INSERTED)
END$$

Upvotes: 0

Views: 3299

Answers (1)

Dawlys
Dawlys

Reputation: 188

A trigger is not a cronjob, you can also make something like :

CREATE TRIGGER my_first_trigger BEFORE INSERT employees
FOR EACH ROW
BEGIN
IF NEW.id_employee = 55 THEN
INSERT INTO special_employees VALUES (NEW.id_employee, NEW.name);
END IF;
END $$

You juste have to adapt this phpmyadmin-mysql query.

Note : I said phpmyadmin-mysql query because actually "END $$" is used only with phpmyadmin. Normally, we use a system of delimiter.

Upvotes: 2

Related Questions