db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@apache.org>
Subject Re: Derby Trigger Query
Date Mon, 10 Apr 2006 17:40:21 GMT
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.




Mime
View raw message