如何在sqlite数据库中创建触发器?
我必须在 SQLite 数据库中创建触发器。
数据库中有 3 个表
questions (question_id)
options (option_id, Question_id)
answers (answer_id, Question_id)
每当从 < 中删除任何行时code>question 表中,option
和 answer
表中相应的数据也应删除。
我正在尝试使用
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除第一个
DELETE
语句后的AND
:Remove the
AND
after the firstDELETE
statement:尝试将“AND”替换为“;”如果您仍然收到错误,请在此处发布错误的文本
try replacing the "AND" with ";" and it you still get an error, post the error's text here