How do we update the table with the SQL trigger?



  • How do we update the table with the SQL trigger? I'm updating the table. test_trigger which has a trigger to update the table table_forum♪ But I can't understand how to update it. table_forum if any data have changed test_trigger♪ How can the value be transferred to the trigger 1,000 and 200which I'm putting in the table test_trigger?

    Updating. test_trigger:

    UPDATE test_trigger SET test_name=1000  WHERE  test_name=200;
    

    Here's the trigger of the table. test_trigger:

    BEGIN
    SET foreign_key_checks =  0 ; 
      UPDATE  table_forum  
      SET  forum2=как тут передать значение 1000 из UPDATE?  
      WHERE  forum2=как тут передать значение 200 из UPDATE?;
    SET foreign_key_checks =  1 ;
    END
    

    Note: Trigger with AFTER parameter. I mean, first the table is updated. test_trigger and because table_forum



  • We need to use the alias. NEW and OLD
    OLD - it's a record before change.
    NEW - it's a recording after change.

    I mean, your option would be:

    BEGIN
    SET foreign_key_checks =  0 ; 
     UPDATE table_forum  SET forum2=NEW.test_name WHERE forum2=OLD.test_name
    SET foreign_key_checks =  1 ;
    END
    

    It can be used as a trigger. BEFORE UPDATEand AFTER UPDATE




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2