1

Is it possible to chain triggers on multiple tables?

Primary table : Questions

  id     int

Secondary table : Answers

  id          int
  id_parent   int

Additional tables

AnswersVotes

  id_answer   int

AnswersViews

  id_answer   int

I need to create chain of actions if I delete a row from table questions

Is it possible to create trigger on table question which would delete rows in answers and also add another trigger on table answers which would delete rows in answersvotes and also answerviews?

Or do I need to add all delete calls in first trigger?

1 Answer 1

1

You can do it either way - either with a trigger on Questions that deletes from all three tables, or by individual triggers on Questions and Answers, where the Answer trigger gets fired by the deletion in Questions. I would suggest it makes more sense to have the separate triggers, in case one answer is deleted from a question.

Or you can set up cascade deletion on the relationships.

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

Comments

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.