-1

我正在尝试使用触发器来插入 vlaue。我有 2 个表连接到一起收集问题和论文。问题有这些列(question_id 主键,correct_answer varchar),我已经插入了值

插入问题值(1,“B”)

论文有这些列(Question_id 外键,student_answer varchare,分数整数)

如果 student_answer 等于 correct_answer 然后插入到分数 1 否则 0 触发器应该在插入纸后工作

这是我的触发器代码

      create trigger if not exists insert_score after insert on paper
      for each row
      when (select * from paper,question 
            where question.question_id = paper.question_id 
            and question.correct_Answer = paper.student_Answer)
      begin 
            insert into paper (Score) values (1);
            end
4

1 回答 1

0
CREATE TRIGGER IF NOT EXISTS set_score
AFTER INSERT ON paper
FOR EACH ROW
WHEN NEW.score IS NULL
BEGIN
    UPDATE paper
    SET Score = EXISTS (SELECT *
                        FROM question
                        WHERE question_id = NEW.question_id
                          AND correct_Answer = NEW.student_Answer)
    WHERE rowid = NEW.rowid;
END;
于 2013-06-01T17:13:54.977 回答