Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2010
    Posts
    7

    Unanswered: Mysql trigger in same table.

    hi all,

    i'm in need of creating a trigger in mysql.

    that is insert and update should done in same table.

    inserting a row in one column and by that update should be done in the another column of same table.


    i worked but its showing the error as "Updating a row is not allowed in after trigger"

    help needed in the best way.

    thanks in advance..

  2. #2
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    Can you post what you have so far?
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  3. #3
    Join Date
    Aug 2010
    Posts
    7

    Mysql trigger in same table.

    DELIMITER |
    CREATE TRIGGER trg_login after insert ON login
    FOR EACH ROW
    BEGIN
    IF new.login_col2= new.login_col2 THEN SET new.login_col3 ='value_one';
    END IF;
    END
    |
    DELIMITER ;

  4. #4
    Join Date
    Sep 2009
    Location
    San Sebastian, Spain
    Posts
    880
    I am not sure whether your code is correct. You have an IF statement with a condition that will always be true i.e. IF new.login_col2= new.login_col2.

    But I think the issue that you are facing here is that you are triggering after the record has been inserted. As a result, setting the NEW.login_col3 will not have any impact as the row is already in the database. Try doing the same thing before insert and this should work.
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    http://www.it-iss.com
    Follow me on Twitter

  5. #5
    Join Date
    Aug 2010
    Posts
    7

    Mysql trigger in same table.

    ya. thanks. i got worked my trigger in before insert.

Posting Permissions

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