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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:41:21+00:00 2026-06-09T11:41:21+00:00

I am trying to create a Trigger for a table that UDATES. I thought

  • 0

I am trying to create a Trigger for a table that UDATES. I thought I could do this with multiple Triggers but I guess MySQL does not support multiple triggers on one table for the same type. So I a forced to include this into one trigger.

Basically I have trying to insert a new record into a different table based on what is updated in the current table.

Here is what I have so far and it works:

BEGIN
-- Definition start
INSERT INTO prices (stationID, price, type, 
prevPrice, prevDate, dateCreated, apiKey, uid) 
VALUES(NEW.stationID, NEW.regPrice, 'reg', OLD.regPrice,
OLD.regDate, NEW.regDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
-- Definition end
END

What I need to happen is the type may change based on what type the user gives. Since the user may only update one type at a given time. I was thinking about an IF IF THEN statement but I wasn’t sure how to get it to work. I was thinking I could use a String value of the column name to use in the IF statement but I an not sure if that is possible.

Something like this:

    BEGIN
    -- Definition start
    IF(type == 'reg') THEN
    INSERT INTO prices (stationID, price, type, 
    prevPrice, prevDate, dateCreated, apiKey, uid) 
    VALUES(NEW.stationID, NEW.regPrice, 'reg', OLD.regPrice,
    OLD.regDate, NEW.regDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
    END IF;
    -- Definition end
    END
  • 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-09T11:41:23+00:00Added an answer on June 9, 2026 at 11:41 am

    I was able to use IF THEN ELSE to complete the transaction. Then I tested the condition for a NULL value. If it is TRUE I then ran my code. Now for some reason it only does one INSERT command even though the UPDATE is for more than one. Any thoughts on this?

    BEGIN
    -- Definition start
    IF(NEW.regPrice IS NOT NULL) THEN
    INSERT INTO prices (stationID, price, type, 
    prevPrice, prevDate, dateCreated, apiKey, uid) 
    VALUES(NEW.stationID, NEW.regPrice, 'reg', OLD.regPrice,
    OLD.regDate, NEW.regDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
    
    ELSEIF(NEW.midPrice IS NOT NULL) THEN
    INSERT INTO prices (stationID, price, type, 
    prevPrice, prevDate, dateCreated, apiKey, uid) 
    VALUES(NEW.stationID, NEW.midPrice, 'mid', OLD.midPrice,
    OLD.midDate, NEW.midDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
    
    ELSEIF(NEW.prePrice IS NOT NULL) THEN
    INSERT INTO prices (stationID, price, type, 
    prevPrice, prevDate, dateCreated, apiKey, uid) 
    VALUES(NEW.stationID, NEW.prePrice, 'pre', OLD.prePrice,
    OLD.preDate, NEW.preDate, NEW.lastApiUsed, NEW.lastUpdatedBy);
    END IF;
    -- Definition end
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to update a table according to this trigger: CREATE TRIGGER alert
I am trying to create an update trigger in MySQL Community Server 5.5.16 but
I am trying to create a Trigger, that will update the History Table with
Trying to create an Oracle trigger that runs after a table is updated in
I'm trying to create a trigger that monitor changes on a table and then
This is schoolwork.. I'm trying to create a table that has a default date
I was trying to create a trigger that after inserts in a table, inserts
I'm trying to create a trigger on my table, so that when I insert
I'm trying to create a basic database trigger that conditionally deletes rows from database1.table1
I am trying to create a trigger to update another table with a condition

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.