These two commands let you add and remove triggers for tables in a database.
CREATE TRIGGER ON TableName
FOR INSERT | UPDATE | DELETE AS lTrigger
DELETE TRIGGER ON TableName
FOR INSERT | UPDATE | DELETEA trigger is a piece of code that runs under certain conditions. Visual FoxPro supports three kinds of triggers: Insert, Update and Delete. The Insert trigger for a table fires when you append a record and when you RECALL a deleted record. The Update trigger fires when you modify a record, and the DELETE TRIGGER fires when you delete a record. Buffering postpones triggers until you do something that attempts to commit the change.
Although lTrigger can be a simple expression, usually it's a call to a routine (in fact, most often a stored procedure) that returns either .T. or .F. If a trigger returns .F., the current error handler (yours or FoxPro's) is called.
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.)
In VFP 7, if the database has Database Events turned on, CREATE TRIGGER and DELETE TRIGGER fire the BeforeModifyTable and AfterModifyTable events.
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.AfterModifyTable, BeforeModifyTable, Create Database, Create Table, Modify Database, _TriggerLevel, Zap
