I have two tables say tab1, tab2
here tab1 is the parent table of tab2, Both have triggers enabled say tab1_trg, tab2_trg. Also in tab2_trg there is a SELECT on tab1.
Now I try to delete some records in tab1, it throws error:
ora-04091 table is mutating trigger/function may not see it
ora-04088 error during execution of trigger tab2_trg
I got the issue that I can not select a table that is being changed at the same time.
But I am not getting this error while constraints are disabled, error is occurring only when constraints are enabled.
Any idea ?
Thanks in Advance
Best Answer
This is normal if you have your FK constraint defined with the
ON DELETE CASCADE
option. When you delete from tab1, that will cause deletes from tab2 also because of the constraint definition. If you disable the constraint, rows from tab2 will not be deleted, the trigger on tab2 will not even run. Below is an example:If you try to delete now, you will get the infamous table is mutating error:
Now with the constraint disabled:
Obviously, this works.
You should rethink/rewrite your trigger or constraint considering the above.