Unix Technical Forum

Help with a trigger

This is a discussion on Help with a trigger within the DB2 forums, part of the Database Server Software category; --> [8.2.1 UDB on linux] I've got two tables, one holding the current price of a product, and one to ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 05:19 AM
James Foreman
 
Posts: n/a
Default Help with a trigger

[8.2.1 UDB on linux]

I've got two tables, one holding the current price of a product, and
one to hold all prior versions;

CREATE TABLE product_pricing (product varchar(10), price decimal (9,
2), last_changed date);
CREATE TABLE product_pricing_history (product varchar(10), price
decimal (9, 2), start date, end date);

Every time update the price in the product_pricing table, I want the
old value to be inserted into the product_pricing_history table. So I
thought this would work:

CREATE TRIGGER price_history_tr
NO CASCADE BEFORE UPDATE OF price ON product_pricing
REFERENCING OLD as oldprice
FOR EACH ROW
BEGIN ATOMIC
INSERT INTO product_pricing_history (product, start, end, price)
VALUES (oldprice.product, oldprice.last_changed, current date,
oldprice.price);
END

However, I get back SQLSTATE 42987: The statement is not allowed in a
procedure or trigger.

Am I doing something blatantly wrong here, or should I take this up
with IBM Support? Being new to triggers, I'm working from the online
doco, and I can't see what in particular I might be doing that's wrong
(
http://publib.boulder.ibm.com/infoce...n/r0000931.htm
)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 05:19 AM
Benjamin Gufler
 
Posts: n/a
Default Re: Help with a trigger

Hi James,

James Foreman wrote:
> CREATE TRIGGER price_history_tr
> NO CASCADE BEFORE UPDATE OF price ON product_pricing
> REFERENCING OLD as oldprice
> FOR EACH ROW
> BEGIN ATOMIC
> INSERT INTO product_pricing_history (product, start, end, price)
> VALUES (oldprice.product, oldprice.last_changed, current date,
> oldprice.price);
> END
>
> However, I get back SQLSTATE 42987: The statement is not allowed in a
> procedure or trigger.


Afair, inserting data in other tables is not allowed in DB2 before
triggers. Try using an "after update" trigger, that should work.

hth,
Benjamin
--
11.+12.11.2005: SFSCon 2005
see http://www.sfscon.it
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 05:19 AM
James Conrad StJohn Foreman
 
Posts: n/a
Default Re: Help with a trigger

Thanks for that - all sorted

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:30 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com