Creates a Delete, Insert, or Update trigger for a table.

CREATE TRIGGER ON TableName   FOR DELETE | INSERT | 
UPDATE AS lExpression

Parameters

TableName

Specifies the table in the current database for which a trigger is created.

FOR DELETE | INSERT | UPDATE

Specifies the type of trigger Visual FoxPro creates.

If a trigger of the type you specify already exists and SET SAFETY is ON, Visual FoxPro asks you if you would like to overwrite the existing trigger. If SET SAFETY is OFF, the existing trigger is automatically overwritten.

AS lExpression

Specifies the logical expression evaluated when the trigger occurs. lExpression can be a user-defined function or a stored procedure that returns a logical value. Stored procedures are created for a table with MODIFY PROCEDURE.

A user-defined function or a stored procedure can use AERROR( ) to determine the name of the table for which the trigger occurred and the trigger type.

If lExpression evaluates to true (.T.), the command or event that caused the trigger to occur is executed.

If lExpression evaluates to false (.F.), the command or event that caused the trigger to occur is not executed. If an ON ERROR procedure is in effect, the ON ERROR procedure is executed instead of the command or event. If an ON ERROR procedure is not in effect, the command or event is not executed and Visual FoxPro generates an error message.

Expand imageRemarks

Expand imageExample

Expand imageSee Also