This lesson covers the basic syntax of a trigger and describes some special variables that can only be used in triggers.
Check the following graphic for syntax and an example of a trigger.
There are two sets of variables that you can use when coding your triggers:
- :OLD.columnname: Each value (including null values) found in the row before it is updated or deleted can be referenced by using the :OLD.columnname variables.
- :NEW.columnname: The new value that will be inserted or updated into the row before it is updated or inserted can be referenced by using the :NEW.columnname variables.
Look at the MouseOver for an example of the code and the values when using these variables. The MouseOver shows you the CREATE TRIGGER command for a trigger on the PRODUCT table.
The next line shows you the current values in one row of the PRODUCT table. Finally, an UPDATE command is used to illustrate the new values that are going to be updated into that same row in the PRODUCT table. Place your mouse over the variables in the trigger code to view the value that each one contains when the trigger is fired for the update.