开发者

How can I create a trigger in sqlite database?

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 WHE开发者_运维问答RE 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


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;


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜