IBM i GYMN – SECOND SECTION: “Data access layer – Triggers”

After I discussed a bit on procedures and how to create them (see the previous post, I would now show you something about TRIGGERS.

As you can see you could launch the trigger creation by the menu ‘Trigger’ on your schema. I will discuss only about SQL trigger, not External trigger:


A window like this will be opened. Then you should indicate trigger name and schema and the table name and schema of the table that will be interested in trigger link:


Then you should specify when this trigger will be executed (INSERT, CANCEL, UPDATE) and if it happens before or after the events:


If you choose UPDATE you could select the fields to update by using the following list and the apposite button to add:


In the next screen you specify if the trigger is launched for every interested row or only one time:


And then you could specify if the trigger is activated after all the operations on rows are completed or after a single operation on row:


With the next screen you should specify the body of your trigger. A list of example will help you to define your conditions. An “SQL Assistant” and a “Syntax check” button will help you to define correct rules:

In this case I called the procedure I previously created and I checked the call:


At the end you will see your trigger in the trigger list or in the list related to all the objects:


You could also generate the SQL script by using the right click on your trigger and save it if you want:




Note that if you come back in your trigger you can’t change the values previously set:


Leave a Reply

Your email address will not be published. Required fields are marked *