From: Daniel John Debrunner <[EMAIL PROTECTED]>
Reply-To: "Derby Discussion" <[email protected]>
To: Derby Discussion <[email protected]>
Subject: Re: Derby Trigger Query
Date: Mon, 10 Apr 2006 10:40:21 -0700
Peter Bowman wrote:
> Hi All,
>
> I have a trigger like:
>
> DROP TRIGGER RULE_10A;
>
> CREATE TRIGGER RULE_10A
> AFTER INSERT ON PLAN_NAME_TABLE
> REFERENCING NEW AS NEWROW
> FOR EACH ROW MODE DB2SQL
> INSERT INTO PLAN_NUTRIENT_TABLE (PLAN, NUTRIENT, NUTRIENT_TYPE,
> UNITS) VALUES (NEWROW.PLAN, 'Total Fat', 'Fat', 'g');
>
>
> which inserts a new row into a table whenever a new row is inserted
into
> another table, but is it possible to use a single trigger to insert
> several rows into the same table or do I have to write a separate
> trigger for each insert.
No. The VALUES clause supports multiple rows.
INSERT INTO PLAN_NUTRIENT_TABLE (PLAN, NUTRIENT, NUTRIENT_TYPE,UNITS)
VALUES (NEWROW.PLAN, 'Total Fat', 'Fat', 'g'),
(NEWROW.PLAN, 'Marmite', 'Vitamin B', 'mg');
See
http://db.apache.org/derby/docs/10.1/ref/rrefsqlj11277.html
Dan.