Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 34230 invoked from network); 31 Aug 2005 12:00:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 31 Aug 2005 12:00:13 -0000 Received: (qmail 53486 invoked by uid 500); 31 Aug 2005 12:00:12 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 53465 invoked by uid 500); 31 Aug 2005 12:00:11 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 53452 invoked by uid 99); 31 Aug 2005 12:00:11 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Aug 2005 05:00:11 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [192.18.98.36] (HELO brmea-mail-4.sun.com) (192.18.98.36) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Aug 2005 05:00:25 -0700 Received: from phys-gadget-1 ([129.156.85.171]) by brmea-mail-4.sun.com (8.12.10/8.12.9) with ESMTP id j7VBxtTY029791 for ; Wed, 31 Aug 2005 06:00:09 -0600 (MDT) Received: from conversion-daemon.gadget-mail1.uk.sun.com by gadget-mail1.uk.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) id <0IM3003015BC91@gadget-mail1.uk.sun.com> (original mail from Kristian.Waagan@Sun.COM) for derby-user@db.apache.org; Wed, 31 Aug 2005 12:59:55 +0100 (BST) Received: from [129.159.112.188] (khepri17.Norway.Sun.COM [129.159.112.188]) by gadget-mail1.uk.sun.com (iPlanet Messaging Server 5.2 HotFix 1.24 (built Dec 19 2003)) with ESMTPA id <0IM30073O5BURX@gadget-mail1.uk.sun.com> for derby-user@db.apache.org; Wed, 31 Aug 2005 12:59:54 +0100 (BST) Date: Wed, 31 Aug 2005 13:59:53 +0200 From: Kristian Waagan Subject: Re: Derby and Triggers In-reply-to: To: Derby Discussion Message-id: <43159BB9.3070904@Sun.com> Organization: Sun Microsystems Inc. MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:1.7.10) Gecko/20050720 Thunderbird/1.0.6 Mnenhy/0.7.2.0 References: X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Hello, I have found using triggers in Derby a little difficult myself. There are several things to watch out for. I will try to give you a few pointers to get you going, but I am no expert, and would appreciate if someone with more knowledge corrected me and provided further information. For your information, the CREATE TRIGGER statement is described in the Reference manual and more information can be found in the Developer's Guide. First of all, you can only specify a single SQL statement for the trigger. You can have several triggers for the same event on the same table. If you can't express the required actions in a single SQL statement, or with multple triggers, you can write a database-side JDBC procedure and invoke it in the trigger. Second, a trigger with (NO CASCADE) BEFORE does not allow UPDATE, INSERT or DELETE statements as the triggered SQL statement. So my proposal for the trigger, which I am very uncertain if is the best one, is: CREATE TRIGGER ATV_tr1 AFTER INSERT ON tab1 REFERENCES NEW AS NEW FOR EACH ROW MODE DB2SQL UPDATE tab1 SET neu_date = CURRENT_DATE WHERE tab1.'some-unique-field' = NEW.'some-uniqe-field'; Is there a way to operate only on the affected row(s), instead of using the WHERE clause to select to correct row? Other comments? -- Kristian Joachim G Stumpf wrote: > > Hi, > i have to convert SQL Syntax to DERBY from Interbase. > I use Derby 10 and customer uses 10.1 . So i downloaded Alpha version of > reference Doku. > > Now i have to define a trigger > > Original > CREATE TRIGGER "ATV_tr1" FOR "tab1" > ACTIVE BEFORE INSERT POSITION 0 > as > declare variable bId integer; > begin > select id_ from tab2 where bez_ = user into :bId; > if ( bId IS NULL ) then bId = 0; > new.xn_b_id_ = bId; > new.xad_b_id_ = bId; > new.neu_date_ = 'now'; > new.aend_date_ = 'now'; > end > ; > > I found db2 syntax which is similar to Derby. > > create trigger atv_basis > no cascade before > insert on ADM_TR_VORGABE_BASIS > referencing new as new > for each row mode db2sql > begin atomic > set new.neu_datum_ = CURRENT_DATE; > set new.aend_datum_ = CURRENT_DATE; > > end; > > This isn't working too. > Can somebody help me out? > > > mfg > Joachim Stumpf DB2 Technical presales support > Tel.: (+49) -7034-15-3276 Fax: (+49)-7034-15-3400 > Internet: stumpfj@de.ibm.com Mobil: (+49)-172-733 9453 > > Developersite: http://www.ibm.com/software/data/developer > Forum: > http://www-106.ibm.com/developerworks/forums/dw_forum.jsp?forum=492&cat=19