Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8719521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:49:07+00:00 2026-06-13T06:49:07+00:00

I have three tables: A and B The relationship is A can have many

  • 0

I have three tables: A and B
The relationship is A can have many B
So B has a reference to the A.id as one of its columns

Table A
|id|date|...

Table B
|id|A_id|...

I have created an Oracle trigger on table A so that when it is updated it updates an A_Mod table.

This trigger is

CREATE OR REPLACE TRIGGER TR_A_INSERT_UPDATE
AFTER  INSERT OR UPDATE ON A
FOR EACH ROW
BEGIN
    INSERT INTO A_Mod values(..., :new.date, ...)
END;

This works fine 🙂

My problem si creating the trigger for table B.

The trigger is:

CREATE OR REPLACE TRIGGER TR_B_INSERT_UPDATE
     AFTER  INSERT OR UPDATE ON B
     FOR EACH ROW
     DECLARE
       ts TIMESTAMP;

     BEGIN
   SELECT aa.date INTO ts FROM B bb 
       INNER JOIN A aa ON a.id = bb.A_id
       WHERE bb.id = :new.id;

       INSERT INTO A_Mod values(..., :new.date, ...)
    END;

This trigger is reading the ID of the updated line in table B and then getting the date from the corresponding row in table A. It then tries to insert it into A_Mod

The problem is I get a mutating error

Error report:
SQL Error: ORA-04091: table B is mutating, trigger/function may not see it
ORA-06512: at "TR_B_INSERT_UPDATE", line 5
ORA-04088: error during execution of trigger 'TR_B_INSERT_UPDATE'
04091. 00000 -  "table %s.%s is mutating, trigger/function may not see it"
*Cause:    A trigger (or a user defined plsql function that is referenced in
           this statement) attempted to look at (or modify) a table that was
           in the middle of being modified by the statement which fired it.
*Action:   Rewrite the trigger (or function) so it does not read that table.

Looking at the docs I can remove this error by removing the FOR EACH ROW line and having the trigger fire once per statement rather than once per row. Unfortunately I am using an ORM mapper so do not control how the updates happen. I think there would be times when the update could cover multiple rows.

The docs say something about creating a temporary table but I am not sure how this would help. Would I have to create a temporary table inside the trigger, create a trigger on this temporary table which then updates A_Mod, update this temporary table when the trigger is fired and then delete everything after?

Any tips greatly appreciated.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:49:08+00:00Added an answer on June 13, 2026 at 6:49 am

    It doesn’t appear that there is any reason in your trigger on B to query the B table. You should be able to simply query A using the :new.a_id

    CREATE OR REPLACE TRIGGER TR_B_INSERT_UPDATE
      AFTER  INSERT OR UPDATE ON B
      FOR EACH ROW
    DECLARE
       ts TIMESTAMP;
    BEGIN
      SELECT a.date 
        INTO ts 
        FROM A a
       WHERE a.id = :new.a_id;
    
      INSERT INTO A_Mod values(..., :new.date, ...)
    END;
    

    From a data modeling standpoint, however, I would be very concerned if a trigger on a child table needed to query any information from the parent table or to insert data into the same history table that the parent table writes to. That seems likely to indicate a normalization issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that has a one to many relationship with itself. Each
Basicall I have three Tables Users Roles and USerRoles with Many to many Relationship.
I've just gone blank. I have a many to many relationship with three tables.
I have three tables: posts, tags and posts_has_tags (which facilitate the many-to-many relationship between
I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
I have three tables/models. User, Alliance and Alliance_Membership. The latter is a join table
I have a database structure that has two one-to-many relationships. I have a website,
I have a Mysql table where it combines three tables. This table stores some
can it make sense for one table to have multiple foreign keys? Suppose I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.