Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Hi Bob.
> Here's a simple problem that I can't quite figure out. I'm creating a database to keep track of donations. Contacts are in one table, and donations are in another. I want to create an update trigger to test if the amount was changed and, if so, add the amount to the persons total in the contacts table; but if the amt was not changed, to leave the total unchanged.
You can use GETFLDSTATE() (see the VFP help for syntax) to determine if the amount field changed or not. If so, use OLDVAL() to back the former value out of the total and then add the current amount to the total.
Of course, purists would say that the contacts table shouldn't have a total field but instead it should be calculated whenever required by summing the amounts from the donations table. This prevents out of sync issues. For example, the update trigger can recalculate the total when the amount changes, but you also have to do something similar in the insert trigger (when a donation record is added) and delete trigger (when a record is deleted).
Doug
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement