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

  • SEARCH
  • Home
  • 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 3724874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T06:47:58+00:00 2026-05-19T06:47:58+00:00

I have an industrial system that logs alarms to a remotely hosted MySQL database.

  • 0

I have an industrial system that logs alarms to a remotely hosted MySQL database. The industrial system inserts a new row whenever a property of the alarm changes (such as the time the alarm was activated, acknowledged or switched off) into a table named ‘alarms’.

I don’t want multiple records for each alarm, so I have set up two database triggers. The first trigger mirrors each new record to a second table, creating/updating rows as required. The second table (‘alarm_display’) has the ‘Tag’ column set as the primary key. The ‘alarm’ table has no primary key. The code for this trigger is:

CREATE TRIGGER `mirror_alarms` BEFORE INSERT ON `alarms`
  FOR EACH ROW 
    INSERT INTO `alarm_display` (Tag,...,OffTime) 
    VALUES (new.Tag,...,new.OffTime) 
    ON DUPLICATE KEY UPDATE OnDate=new.OnDate,...,OffTime=new.OffTime

The second trigger should execute after the first and (ideally) delete all rows from the alarms table. (I used the Tag property of the alarm because the Tag property never changes, although I suspect I could just use a ‘DELETE FROM alarms WHERE 1’ statement to the same effect).

CREATE TRIGGER `remove_alarms` AFTER INSERT ON `alarms`
  FOR EACH ROW DELETE FROM alarms WHERE Tag=new.Tag

My problem is that the second trigger doesn’t appear to run, or if it does, the second trigger doesn’t delete any rows from the database.

So here’s the question: why does my second trigger not do what I expect it to do?

  • 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-19T06:47:59+00:00Added an answer on May 19, 2026 at 6:47 am

    The explanation can be read here: http://dev.mysql.com/doc/refman/5.0/en/stored-program-restrictions.html

    Within a stored function or trigger,
    it is not permitted to modify a table
    that is already being used (for
    reading or writing) by the statement
    that invoked the function or trigger.

    This is your problem and your trigger ends with error #1442.

    The table alarms is already being used by the statement that invoked your trigger (the insert). This essentially means you cannot modify alarms with a delete trigger.

    Cheers!

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

Sidebar

Related Questions

I have got a server that controls a complicated industrial system. We need to
I have written a xml/php document that is pulling from a Magento Commerce database,
I have an Industrial HMI written by a third party in C++ that communicates
We have an industrial system, which can be interfaced using some C++ DLLs given
I have a button control that has its Content property bound to a boolean
I have a unique industrial application where I do not want the Windows CE
I have this JSON: var myVar = { 9:Automotive & Industrial, 1:Books, 7:Clothing };
Have a network location that shows paths in the 8.3 short format. I need
Have data that has this kind of structure. Will be in ascending order by
Have data that has this kind of structure: $input = [ { animal: 'cat',

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.