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 > Key value in trigger

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-21-05, 06:35
brokerics brokerics is offline
Registered User
 
Join Date: Dec 2005
Posts: 1
Key value in trigger

hi people

i tried to create a trigger , such that whenever there is an insertion into a database, i try to retrieve that row contents and insert into another table.
now how do i access the key value of the current row that was just inserted??

my current trigger is
INSERT INTO EAIUSER.xworlds_events
(event_id,connector_id,
object_key,
object_name,
object_verb,
event_priority,
event_status)
VALUES
(NEXTVAL for myseq,'JDBC_X',
'EID',
'EMPL',
'Create',
0,
0);

the EID is the object key. i tried something like CURRENT.EID .didnt work
cud someone help ?


DB2 VERSION V 8.1 ENTERPRISE SERVER EDITION
FIX PACK 4
WINDOWS XP
Reply With Quote
  #2 (permalink)  
Old 12-21-05, 08:53
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Your trigger should look like this:

CREATE TRIGGER MyTrigger AFTER INSERT ON MyTable
REFERENCING NEW as newdata FOR EACH ROW MODE DB2SQL
INSERT INTO MyLogTable (keycol,col2,col3)
VALUES
(newdata.keycol,newdata.col2,newdata.col3)

HTH

Andy
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