how to write mysql trigger

前端 未结 2 406
我在风中等你
我在风中等你 2021-01-15 03:15


there are two tables
table A

if user use this query \"insert into A values(abc,1,50);\"

then trigger should check student_nam

2条回答
  •  醉梦人生
    2021-01-15 03:35

    You can simply this by using On Duplicate Key Update . Add a unique key on student name / ID then use the following code in your trigger

    begin
       insert into summary_score (name,number,all_marks)
       values(new.name,new.marks,new.score)
       on duplicate key update all_marks=old.all_marks+new.student_marks
      where B.Name=new.Name;
    end $$
    

提交回复
热议问题