Skip to content
Advertisement

What’s wrong with this PL/SQL Trigger?

I have this table, and I want to create a trigger on Magazine, that verifies “after insert” if the name of the Magazine inserted is either Vogue or People.

If it’s not one of them, it gets deleted.

Table:

  • MAGAZINE (ISBN, MAG_NOM, PRIX_Mois);

My trigger:

But the problem is my teacher told me:

This is not suitable for every situation

I don’t know what that means, can you please help me improve this trigger?

It seemed correct to me, what did I do wrong ?

Advertisement

Answer

You don’t need to use a DML, convert the trigger into this

and you would get table is mutating error in this case due to using the table, on which the trigger is created, within the trigger’s body.

Moreover it would be far better to add a check constraint than creating a trigger such as

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