0

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$$
1
  • 1
    a trigger isn't a cronjob Commented Aug 1, 2013 at 8:35

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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. Code adove

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.