MySQL Forums
Forum List  »  Newbie

Re: Update a filed with sum from another table
Posted by: Phillip Ward
Date: September 15, 2023 08:06AM


I have a Javascript in the background, so every time the job is opened it will auto update the fields

An item might be updated right after your javascript finishes.
From that point until your javascript runs again, your invoice-level total is wrong.

You database must be your Single Source of Truth.

If your invoices have only a few items each, I would strongly recommend calculating the total "on the fly".
If they really do have a lot of items (and I'm talking thousands of items, here) then use a database Trigger to maintain the invoice-level total when any individual item changes (or is added or deleted).
Trying to do it periodically with a batch program is a recipe for disaster.

Regards, Phill W.

Options: ReplyQuote

Written By
Re: Update a filed with sum from another table
September 15, 2023 08:06AM

Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.