Subject Re: [firebird-support] Re: Help with a trigger/procedure
Author Fabio Gomes
Hi guys,

I have another question :)

The solution using SUM() and a table with quantitys is working fine now, but
i have another doubt.

I have my products table:

product_id
description
quantity

This quantity, is the sum of all the records of the product in the other
table, wich would be the best way to keep it updated?

Should i use a query with a join and SUM() each time i need to see the
quantity?

Or sould i create a view? or maybe a computed field (i dont have any idea
how it works btw)? Or can i even use a trigger?

Which would be the best way to do it?


Thanx in advance,

-Fábio.



On 9/12/06, Ann W. Harrison <aharrison@...> wrote:
>
> Alan McDonald wrote:
> >
> > But a transaction started by another user before the sum transaction is
> > started and seemingly intent on updating a record to be summed but not
> > committed until after the summing and deleting is committed will ...
> ahhh
> > hopefully you're getting my drift... will either cause an exception on
> > update or block the delete or just not update since the record doesn't
> exist
> > anymore.
>
> There are two definitions of "safety" in this case. One is
> that the summation will accurately reflect the contents of
> the records that were read and deleted. The other is that
> the procedure is guaranteed not to conflict with other
> concurrent actions.
>
> The first is possible, assuming your using concurrency/snapshot
> transactions - not read-committed, the summing and replacing
> can be done safely with other transactions active. It may get
> an error, but it won't get a wrong answer. If some other
> transaction modified one of the records being summed before the
> delete, the delete will get an error. If the delete has occurred
> and the other transaction tries to update the record, it will get
> an error.
>
> If the definition of safety is that the procedure can run
> with no chance of errors, then it must be run without other
> transactions modifying the same data. A gateway record could
> be the solution - something you have to modify first before
> making changes to the actual table data.
>
> Regards,
>
> Ann
>
> Regards,
>
> Ann
>
>
>


[Non-text portions of this message have been removed]