Create a trigger in the DB2 Control Center

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.