Topic
  • 1 reply
  • Latest Post - ‏2013-06-01T08:37:54Z by LennartJonsson
pkht
pkht
1 Post

Pinned topic DB2 - Trigger on same table

‏2013-05-30T20:50:50Z |

Hi,

Requirement : There is a table called TabA which has two columns empId, Dept. one empId can work for two department(Dep1, Dep2). Customer will be responsible for updating depart1 through UI, we need to write a code to insert same employee id into department 2 through db script. There is no other conditions. Whenever there is insertion on dept1, there should be trigger to insert same employee id on dept2 column. 

I am not sure how to create a trigger in this case, it would be a great if someone help me on this. 

 

 

  • LennartJonsson
    LennartJonsson
    1 Post

    Re: DB2 - Trigger on same table

    ‏2013-06-01T08:37:54Z  

    Could you please post ddl for the table(s)? If there is one table like:

      

    create table tab
    (    empid int not null
    ,    dept int not null
    ,    dept2 int not null ) @
     

    A trigger like

     

    create trigger trg
    before insert on tab
    referencing new as n
    for each row
        set dept2 = dept @
     

    will do