Saturday, June 20, 2020


MySQL Tips - Before delete trigger for logging


  • Before delete trigger for archiving 
    CREATE TRIGGER ARCHIVE_ON_DELETE
    BEFORE DELETE
    ON TASK_SHEET FOR EACH ROW
    BEGIN
    
    INSERT INTO TASK_SHEET_ARCHIVE
    (id,task_id, asking_time, given, received, comments, status, last_updated, task_sheet_number, channel_id)
    
    
    
    SELECT id, task_id, asking_time, given, received, comments, status, last_updated, task_sheet_number, channel_id
    FROM  TASK_SHEET WHERE id=OLD.id;
    
    
    END
  • Set auto-increment value (due to some change you want to do, need to skip some ids)
    ALTER TABLE contacts AUTO_INCREMENT = 50;



Share Article :
Share/Save/Bookmark