-5

I have one table called number_list which have columns like:

id, name, number, server, status, last_act, user_id, created_at, disable, notify,fcm

I want update last_act when there any changes in status column only. Currently its updating last_act whenever any changes in any column. Let me know if its possible with MySQL. Thanks

SirPeople
  • 4,248
  • 26
  • 46
Priti Patel
  • 21
  • 1
  • 6

1 Answers1

0

Setting up a trigger like the following should accomplish what you have asked.

DELIMITER $$
        CREATE TRIGGER number_list_update_trigger 
        BEFORE UPDATE 
        ON number_list
        FOR EACH ROW
        BEGIN
          if (NEW.status = OLD.status) THEN 
             set NEW.last_act = OLD.last_act;
          END IF;
        END $$
  DELIMITER ;
Gabe Gates
  • 902
  • 1
  • 14
  • 19