|SQL Triggers concept in IBM i DB2|
Triggers provide the way to monitor, alter, and manage the tables when any insert, delete or add operation occurs on the table.
It is very helpful when there is huge dependency present between the tables or if any specific action has to be performed when there is any change happening in the table.
Below are some points to understand the trigger better:
Tracks Database Activity
The trigger gets active only in the case when there is any change happening on the trigger associated table like add, delete and insert.
Enforce Bussiness Rules / Ensure data consistency in the database
In case, when there are multiple tables that are co-related to each other then all the related tables will get in synch with each other when any changes are applied on the trigger associated table and further the action performed by the trigger alters the related table to bring them in synch.
When the trigger is executed a certain set of actions are performed.
Insert,Delete,Update on Table/View
A trigger can be added on insert, delete, the addition of the record in the table or in the View.
Called By Database
When certain actions are performed by the trigger then the actions are called by the database (database management system) itself.
Perform non-database operations
The trigger can also be used by sending messages, email, or other non-database-related operations.
There's also a concept of cascading trigger which will execute the chain of triggers performing multiple sets of action across the application.
Support column-level granularity
A trigger can be added to a specific column of the table rather than the table itself.
Stored procedure/ UDF
SQL triggers are invoked through the database management system on the execution of the triggering operation and it can call SQL stored procedure or UDF.
Read also :
- Syntax for Create Trigger in IBM i AS400
- Simple SQL Trigger Example
- Conditional SQL Trigger Example
- OF Clause in SQL Trigger
- Multiple Event Execution Through SQL Trigger
- Change Row Before Inserting In Table (Before SQL Trigger)
- Stored Procedure calling in SQL Trigger
- Transition Tables in SQL Triggers
- Error Handling in SQL Trigger Using Signalling
- Self Referencing SQL trigger
- INSTEAD OF SQL Trigger (Adding / Deleting / Inserting record in the table through SQL View)
- Trigger Limitations and Program Attributes
- Effects On Trigger When New File Field Is Added
- SYSTRIGGERS Catalog Table for SQL Trigger
- SYSTRIGDEP Catalog Table for SQL Trigger
- SYSTRIGUPD Catalog Table for SQL Trigger
- SYSTRIGCOL Catalog Table for SQL Trigger