From: http://wly719.iteye.com/blog/502578
Due to the needs of the company's projects, I am a developer who cannot get through DB2 to write a trigger. No way. Check the information and record the results.
Right-click the trigger and choose create. The following page is displayed.
Create a trigger name. Select Table view mode and table view name.
Select triggered operation. The page is displayed.
Because the previously selected trigger operation is insert, there is only a new row related name. In the following triggered operation, write the trigger statement. The trigger statement requirements are strict and there are many restrictions.
Paste a simple example
/*
Purpose: when the value of ziduan1 In the Dest table is greater than 110, insert 120,120,120 data to the SRC table. Otherwise, an error is thrown. The error number seems to be 5 characters.
*/
Create trigger administrator. trigger_dest after insert on administrator. DEST referencing new as newrow for each row mode db2sql
Begin atomic
Declare newstr varchar (22 );
Set newstr = newrow. ziduan1;
If (newstr> 110) Then insert into SRC values ('20160301', '20160301'); else signal sqlstate '20160301' ('unseccfull '); end if;
End
The result is as follows:
Click OK.
Many problems were encountered during the experiment,
1: The SQL statements triggered by the before trigger cannot include:
-Modify SQL table functions
-Nested Delete, insert, merge, or update statements