Hackers Guide to Visual FoxPro 7.0
Create Trigger, Delete Trigger
These two commands let you add and remove triggers for tables in a database.| Usage | CREATE TRIGGER ON TableName FOR INSERT | UPDATE | DELETE AS lTrigger DELETE TRIGGER ON TableName FOR INSERT | UPDATE | DELETE |
| | When a trigger returns .F. in a Browse, it bypasses any custom error handler, and FoxPro's default "Trigger failed" message appears. This is generally a concern only in the development environment, however, since your error handler is correctly called when the trigger returns .F. in a grid. |
Triggers cannot change data in the table they belong to. They can (and often do) change data in other tables in the same database.
The RI builder uses triggers to enforce referential integrity. It generates code that is saved with the database's stored procedures and sets the tables' triggers to appropriate calls to that code. (These routines are one example of trigger code that changes other tables.)| | The Delete trigger doesn't fire when you ZAP a table. Although we think using ZAP on a table is a terrible mistake, except on your own test data, this is an absolute violation of the integrity of the database. It leaves a huge landmine in the path of any user who knows enough to be dangerous. |
In VFP 7, if the database has database events turned on, CREATE TRIGGER and DELETE TRIGGER fire the BeforeModifyTable and AfterModifyTable events.
| Example | CREATE TRIGGER ON MyTable FOR INSERT AS MyTrigger * And here's the trigger code PROCEDURE MyTrigger WAIT WINDOW "New record added. Total is now " + ; LTRIM(STR(RECCOUNT())) RETURN .T. |
| See Also | AfterModifyTable, BeforeModifyTable, Create Database, Create Table, Modify Database, _TriggerLevel, Zap |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории