If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > creating a trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-07, 23:02
Solunac Solunac is offline
Registered User
 
Join Date: Jul 2007
Posts: 1
creating a trigger

Hi, everyone, I am new here ...

I have a problem to create a after-trigger (update).

Example tables:

CREATE TABLE R
(
log_num SMALLINT NOT NULL,
int_num SMALLINT NOT NULL,
beg_time TIME NOT NULL,
end_time TIME NOT NULL,

PRIMARY KEY (log_num, int_num),

FOREIGN KEY skrbi(br_int) REFERENCES I (int_num)
);

CREATE TABLE I
(
int_num SMALLINT NOT NULL,
name CHAR(50) NOT NULL,

PRIMARY KEY (br_int),
);

CREATE TABLE S
(
mat_num SMALLINT NOT NULL,
cost NUMERIC(7,2) NOT NULL,
stored NUMERIC(7,2) NOT NULL WITH DEFAULT 0,

PRIMARY KEY (br_mat),
);

CREATE TABLE IS
(
int_num SMALLINT NOT NULL,
mat_num SMALLINT NOT NULL,
norm NUMERIC (7,2) NOT NULL,

PRIMARY KEY (int_num, mat_num),

FOREIGN KEY fks(mat_num) REFERENCES S (mat_num),
FOREIGN KEY fki(int_num) REFERENCES I (int_num)
);

I 1-many IS
S 1-many IS
R many-1 I


When I insert new row into the table R, the adequate rows in table S should be updated. Few or one corresponding fields of column stored (table S) should be less for the size of the few or one corresponending norm (table IS).

I am trying to write an update trigger that will send one or few (depends of the values of table IS) fields from one table (IS) to update one or few fields in another table (S, multiple rows though).



Sorry if I asked something easy or stupid i am new to this, and my english is not so good.
Reply With Quote
  #2 (permalink)  
Old 08-20-07, 08:27
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
Can you correct the CREATE scripts so they run on DB2?
When you've done that, I'll look further into it.
__________________
With kind regards . . . . . SQL Server 2000/2005/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages
Reply With Quote
  #3 (permalink)  
Old 08-20-07, 08:38
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Also, tell us which version of DB2 you are using on which platform. And it would also be good to know the exact error messages you got (or the description of the behavior you see).
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On