CREATE TRIGGER Command Example

The following examples creates an Update trigger which prevents values greater than 50 from being entered in the maxordamt field in the customer table. An error message is generated when the first REPLACE command is executed because the value for the maxordamt field is greater than 50. The second REPLACE command does not generate an error because the value for the maxordamt field is less than or equal to 50.

CLOSE DATABASES

OPEN DATABASE (HOME(2) + 'data\testdata')
USE customer  && Open customer table

* Set trigger on maxordamt field to fail with values <= 50
CREATE TRIGGER ON customer FOR UPDATE AS maxordamt <= 50

ON ERROR  && Restore the system error handler

WAIT WINDOW "Press a key to test trigger with value of 60"+CHR(13);
 +"When you get the error message, press Ignore."
REPLACE maxordamt WITH 60    && Displays an error message
? maxordamt

WAIT WINDOW "Press a key to test with value of 50."
REPLACE maxordamt WITH 50    && Value is accepted
? maxordamt
DELETE TRIGGER ON customer FOR UPDATE  && Remove the trigger