Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating triggers
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00425998
Message ID:
00426019
Vues:
26
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
Fil
Voir

Click here to load this message in the networking platform