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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:29:15+00:00 2026-05-25T23:29:15+00:00

I need to make this trigger work using three tables. Does anyone see a

  • 0

I need to make this trigger work using three tables. Does anyone see a problem?

The ‘qty’ needs to always show the latest quantity from the adds and pulls.

CREATE TRIGGER Upd_Cartons_Qty 
AFTER INSERT ON cartons_added FOR EACH ROW
BEGIN
UPDATE cartons_current SET qty = qty + NEW.add_qty WHERE part_no = NEW.part_no;
END;



TABLE NAME:  cartons_current
+--------------+--------------+-------+-------+
| Column       | Type         | Null  | Key   |
+--------------+--------------+-------+-------+
| part_no      | varchar(20)  | No    | Prim  |
| qty          | int(8)       | No    |       |
+--------------+--------------+-------+-------+

TABLE NAME:  cartons-added
+--------------+--------------+-------+-------+
| Column       |  Type        | Null  | Key   |
+--------------+--------------+-------+-------+
| part_no      | varchar(20)  | No    | Prim  |
| add_qty      | int(8)       | No    |       |
+--------------+--------------+-------+-------+

TABLE NAME:  cartons_pulled
+--------------+--------------+-------+-------+
| Column       | Type         | Null  | Key   |
+--------------+--------------+-------+-------+
| part_no      | varchar(20)  | No    | Prim  |
| pull_qty     | int(8)       | No    |       |
+--------------+--------------+-------+-------+
  • 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-25T23:29:16+00:00Added an answer on May 25, 2026 at 11:29 pm

    1- You cannot use ; as a final delimiter for the end. You need to set a delimiter before the trigger.
    2- A after insert trigger should logically have a prefix ai, not upd.
    3- You cannot change values in a after trigger in the same table the trigger is for. So if you (might) need to change values in cartons_added you need to do that in the before trigger.
    4- On the other hand, you cannot change values in other tables in a before trigger, because these changes might rollback and then you have inconstancy i your tables, so that need to happen in the after trigger.
    5- You can effect multiple tables in a trigger, just do it like the example.

    DELIMITER $$
    
    CREATE TRIGGER ai_Cartons_Qty AFTER INSERT ON cartons_added FOR EACH ROW
    BEGIN
      UPDATE cartons_current SET qty = qty + NEW.add_qty WHERE part_no = NEW.part_no;
      UPDATE cartons_pulled SET x1 = x1 + NEW.add_qty WHERE part_no = NEW.part_no;
    END$$
    
    DELIMITER ;
    

    If you want to alter some value in the triggers own table, don’t use update, use code like below instead:

    DELIMITER $$
    
    CREATE TRIGGER ai_Cartons_Qty BEFORE INSERT ON cartons_added FOR EACH ROW
    BEGIN
      -- Update cartons_added .... will not work.
      -- Use SET NEW.fieldname instead.
      IF NEW.qty_added = 0 THEN 
        SET NEW.qty_added = 1;
      END IF;
    END$$
    
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make this function work everywhere, except IE6-7 $(function(){ window.scrollTo(0,300); }) Please
I have this code and I need to make this work: if ($handle =
Not sure exactly what I need to do to make this work, so my
I Need to make a webpage. asp.net this webpage recieve parameter by using Request.Querystring
This is WebKit browsers specific (meaning that I only need to make it work
I need to make this design: http://www.stephburningham.com/lmg/ into a joomla template but I've never
I need to make a query like this: SELECT PNPDeviceID FROM Win32_NetworkAdapter WHERE AdapterTypeId
Hi I need to make an dynamic array like this: I have a max
So I need to make 3 tabs with query (got this part down), but
I need to make a query to one of Google's services. I read this

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.