Results 1 to 5 of 5

Thread: Help on Trigger

  1. #1
    Join Date
    May 2002
    Posts
    29

    Unanswered: Help on Trigger

    Hi
    I am trying to write a trigger which will update a column in a table (say col A in tab B)as soon as I update records in tab A. This is what I have put down and not implemented as of now. Please correct me if I am wrong some where.

    CREATE OR REPLACE TRIGGER emp_update_trig
    AFTER UPDATE
    ON tab A
    FOR EACH ROW
    DECLARE
    dummy INTEGER;
    BEGIN
    UPDATE tab B Set Col A = :new.Col A where Col B=:Old.Col B;
    END;

    Thanks in advance
    Regards
    Dinesh

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Help on Trigger

    Originally posted by dineshyadav
    Hi
    I am trying to write a trigger which will update a column in a table (say col A in tab B)as soon as I update records in tab A. This is what I have put down and not implemented as of now. Please correct me if I am wrong some where.

    CREATE OR REPLACE TRIGGER emp_update_trig
    AFTER UPDATE
    ON tab A
    FOR EACH ROW
    DECLARE
    dummy INTEGER;
    BEGIN
    UPDATE tab B Set Col A = :new.Col A where Col B=:Old.Col B;
    END;

    Thanks in advance
    Regards
    Dinesh
    Looks OK, except for your 2-word table and column names which I know are only examples, but are very confusing! Also what is the point of declaring dummy?

  3. #3
    Join Date
    May 2002
    Posts
    29
    Andrew
    I will give you the exact scenario..
    I have a employee table which has got a emp_code, emp_workerid and emp_name. I have a login table which has the emp_code and the emp_workerid columns. So whenever I update any entry in the employee table the emp_workerid Column has to get updated in the Login table's emp_workerid column. Can u help me out.
    Regs
    Dinesh

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Originally posted by dineshyadav
    Andrew
    I will give you the exact scenario..
    I have a employee table which has got a emp_code, emp_workerid and emp_name. I have a login table which has the emp_code and the emp_workerid columns. So whenever I update any entry in the employee table the emp_workerid Column has to get updated in the Login table's emp_workerid column. Can u help me out.
    Regs
    Dinesh
    Use your previous example, but replacing example table and column names with the real ones, and it should work as written. Post it here if you want any comments on it.

    However, why store same information in 2 different tables? Seems pointless.

  5. #5
    Join Date
    May 2002
    Posts
    29
    Thanks andrew it worked fine. The reason why we are trying to update the same field in two tables is that initially we used to login into the application using the emp_code as the Username now since we are implementing the Single Authetication policy for all the web based applications we are autheticating the login's using the worker id which was not a mandatory field at the initial stages of our development. Now this was the solution we came up with for minimal code change in the existing application. Thanks for the help once again.
    Regards
    Dinesh

Posting Permissions

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