Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2005
    Posts
    1

    Unanswered: 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

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •