docs.intersystems.com
InterSystems IRIS Data Platform 2019.2  /  Class Definition Reference

Class Definition Reference
Trigger Definitions
Previous section           Next section
InterSystems: The power behind what matters   
Search:  


Describes the structure of a trigger definition.
Introduction
Triggers are code segments executed when specific events occur in InterSystems SQL. InterSystems IRIS supports triggers based on the execution of INSERT, UPDATE, and DELETE commands. The specified code will be executed either immediately before or immediately after the relevant command is executed, depending on the trigger definition. Each event can have multiple triggers as long as they are assigned an execution order.
You can add trigger definitions to persistent classes. They are not meaningful in other kinds of classes.
Details
A trigger definition has the following structure:
/// description 
Trigger name [ keyword_list ]  
{ implementation }
Where:
Example
/// This trigger updates the LogTable after every insert
Trigger LogEvent [ Event = INSERT, Time = AFTER ]
{
    // get row id of inserted row
    NEW id
    SET id = {ID}

    // INSERT value into Log table
    &sql(INSERT INTO LogTable (TableName, IDValue) VALUES ('MyApp.Person', :id))
 
}
See Also


Previous section           Next section
Send us comments on this page
View this book as PDF   |  Download all PDFs
Copyright © 1997-2019 InterSystems Corporation, Cambridge, MA
Content Date/Time: 2019-08-19 05:43:38