0

I have to create trigger in my SQLite database.

There are 3 tables in database

  • questions (question_id)
  • options (option_id, question_id)
  • answers (answer_id, question_id)

Whenever any row is deleted from question table, the corresponding data should also be deleted from option and answer tables.

I am trying to create trigger using

CREATE TRIGGER question_delete
BEFORE DELETE ON questions
FOR EACH ROW BEGIN
DELETE from options WHERE question_id= OLD.question_id AND
DELETE from answers WHERE question_id= OLD.question_id;
END

I get an error. Should I create two different trigger to perform this operation or any changes are required in above statement?

Please let me know.

Thanks Nidhi

1
  • 2
    WHAT error do you get?? It really doesn't help us to know you get "an error" - but you're not telling us what it is!! Commented May 11, 2011 at 11:45

2 Answers 2

2

Remove the AND after the first DELETE statement:

DELETE from options WHERE question_id = OLD.question_id;
DELETE from answers WHERE question_id = OLD.question_id;
Sign up to request clarification or add additional context in comments.

Comments

0

try replacing the "AND" with ";" and it you still get an error, post the error's text here

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.