InDB2 databaseOperation, we often useTriggerThis seems a little difficult for beginners. But it doesn't matter. This article introduces some knowledge about DB2 database triggers and provides an instance for creating triggers. For Beginners, if you don't know much about them, you can also directly apply the following instances to create a trigger. Next let's take a look at this part.
Create a trigger that includes the following parts:
Trigger name :......
Trigger trigger event: insert, delete, update
Activation time: before, after
Granularity: for each statement, for each row
Transition variable:
Old row: indicates the modified value before the event is triggered:
New row indicates the value modified after the event is triggered.
Old table indicates a read-only hypothetical table of all modified rows before the event is triggered.
New table indicates a hypothetical table in which all rows are modified after the event is triggered.
Trigger condition: starting from WHEN, it can contain one or more predicates, including transition variables and subqueries.
Trigger body: it consists of one or more SQL statements.
Create an instance of the DB2 trigger:
- CREATE TRIGGER REORDER
-
- AFTER UPDATE OF ON_HAND, MAX_STOCKED ON PARTS
-
- REFERENCING NEW AS N_ROW
-
- FOR EACH ROW MODE DB2SQL
-
- WHEN (N_ROW.ON_HAND < 0.10 * N_ROW.MAX_STOCKED
-
- AND N_ROW.ORDER_PENDING = 'N')
-
- BEGIN ATOMIC
-
- VALUES(ISSUE_SHIP_REQUEST(N_ROW.MAX_STOCKED -
-
- N_ROW.ON_HAND,
-
- N_ROW.PARTNO));
-
- UPDATE PARTS SET PARTS.ORDER_PENDING = 'Y'
-
- WHERE PARTS.PARTNO = N_ROW.PARTNO;
-
- END
The introduction of the DB2 database trigger is here. I hope this introduction will be helpful to you.