Skip to content
Advertisement

SQL: set trigger to get the sum of rows

This is the results table:

I want to create a trigger that will sum up the rows get_ca1 + get_ca2 ...+ get_exam and store the total in the get_total column. When the rows get_ca1, get_ca2,... get_exam are inserted, the trigger should calculate the total and store in the get_total column.

I just learnt about triggers today so I’m not knowledgeable in it at all. But so far, this is what I tried and it of course threw an error.

Advertisement

Answer

Mysql doesn’t know where your columns belog because you are missing a reference to the NEW row.

Also you can only change values, before the row was inserted

so use

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement