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 7590251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:21:16+00:00 2026-05-30T20:21:16+00:00

I have a little probleme using Triggers in MySQL. Suppose we have 2 tables:

  • 0

I have a little probleme using Triggers in MySQL.

Suppose we have 2 tables:

  • TableA
  • TableB

And 2 Triggers:

  • TriggerA: fires when deleting on TableA and updates TableB
  • TriggerB: fires when deleting on TableB and deletes in TableA

The problem is that when I delete some rows in TableB, TriggerB fires and deletes some elements in TableA, then TriggerA fires and tries to update TableB.

It fails because TriggerA tries to update some rows in TableB that are being deleted.

How can I avoid this circular dependencies?

None of those two Triggers are useless, so I don’t know what am I supposed to do to solve this.

  • 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-05-30T20:21:18+00:00Added an answer on May 30, 2026 at 8:21 pm

    Try to use variable.

    First trigger:

    CREATE TRIGGER trigger1
      BEFORE DELETE
      ON table1
      FOR EACH ROW
    BEGIN
      IF @deleting IS NULL THEN
        SET @deleting = 1;
        DELETE FROM table2 WHERE id = OLD.id;
        SET @deleting = NULL;
      END IF;
    END
    

    Second trigger:

    CREATE TRIGGER trigger2
      BEFORE DELETE
      ON table2
      FOR EACH ROW
    BEGIN
      IF @deleting IS NULL THEN
        SET @deleting = 1;
        DELETE FROM table1 WHERE id = OLD.id;
        SET @deleting = NULL;
      END IF;
    END
    

    And additional AFTER DELETE triggers:

    CREATE TRIGGER trigger3
      AFTER DELETE
      ON table1
      FOR EACH ROW
    BEGIN
      SET @deleting = NULL;
    END
    
    CREATE TRIGGER trigger4
      AFTER DELETE
      ON table2
      FOR EACH ROW
    BEGIN
      SET @deleting = NULL;
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little problem about using jQuery (I really do not know jQuery
I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I have a little problem about Google Maps. I'm using Geocoding (xml) for getting
I have a little problem with a query. I'm selecting data using the between
I have a little problem with adding actions on UITabBarItems. I am not using
I have a little problem, probably easy for you. Im using Core Data. I
Hi all im using a sqlite helper class, but i have a little problem
i have little problem in using my application application having msaccess database if i
I using dropkick js to style dropdown forms but have one little problem. What
I'm making an PhoneGap app using Jquery Mobile, but I have a little problem

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.