MySQL automatic update for specific column instead of whole record

后端 未结 1 772
情话喂你
情话喂你 2021-01-27 14:32

I have a table APPLEVARIETY. It has the following columns:

  • id
  • family
  • color
  • description (TEXT)
  • description_last_update_time (TI
相关标签:
1条回答
  • 2021-01-27 14:50

    No thats not possible using the ON UPDATE CURRENT_TIMESTAMP this will get updated when any column is updated. You may however achieve the same using a trigger. For that you will first need to remove ON UPDATE CURRENT_TIMESTAMP from the table definition. The trigger will look like

    delimiter //
    
    create trigger APPLEVARIETY_update before update on APPLEVARIETY
    for each row 
    begin
      if new.description <> old.description then
        set new.description_last_update_time = now();
      end if;
    end;//
    
    delimiter ;
    
    0 讨论(0)
提交回复
热议问题