Skip to content
Advertisement

Table is mutating, trigger/function may not see it (stopping an average grade from dropping below 2.5)

Here’s the problem:

Create a trigger that prevents any change to the taking relation that would drop the overall average grade in any particular class below 2.5. Note: This trigger is not intended to address the average GPA of any given student, but rather it should address the average grade for all grades assigned in a particular class.

Here’s the schema:

I’m having a terrible time with these triggers, but here’s my attempt to make this work:

I’m obviously doing something wrong because when I then go to update or delete a tuple, I get the error:

Any advice? I’m using Oracle.

Advertisement

Answer

I think you can fix this by rewriting this as a before trigger, rather than an after trigger. However, this might be a little complicated for inserts and deletes. The idea is:

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