1

How do I use the data that was used to trigger the "trigger" in the trigger itself?

For example, lets assume we have a user (user_id) who created a new mission (mission_id) and therefore entered a new row in a table called missions.

Now I want to create a log in a table called log by using that specific user_id and mission_id.

What is that right syntax to do that?

1 Answer 1

1

You access the pseudo rows OLD and NEW to do this. New contains the new data (e.g. Inserts and new Update data), and Old contains the outgoing data (Deletes and old values prior to an update).

CREATE TRIGGER t_missions
  BEFORE INSERT ON Missions
  FOR EACH ROW
BEGIN
   INSERT INTO Log(user_id, mission_id) VALUES(new.user_id, new.mission_id);
END;

SqlFiddle here

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

1 Comment

Can you please show me an example using the case I presented above?

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.