Based on one more step (for those of us who still adhere to the outdated version of MySQL), you can have BOTH protected and default create_stamp file AND automatically update_stamp as follows:
If you have a table like
CREATE TABLE `csv_status` ( `id` int(11) NOT NULL primary key AUTO_INCREMENT, `create_stamp` datetime not null, `update_stamp` timestamp default current_timestamp on update current_timestamp, `status` enum('happy','sad') not null default 'happy' );
Then you can define these triggers on it
drop trigger if exists set_create_stamp ; create definer = CURRENT_USER trigger set_create_stamp BEFORE INSERT on csv_status for each row set NEW.create_stamp = now(); drop trigger if exists protect_create_stamp ; delimiter // create definer = CURRENT_USER trigger protect_create_stamp BEFORE UPDATE on csv_status for each row begin if NEW.create_stamp != OLD.create_stamp then set NEW.create_stamp = OLD.create_stamp; end if; end;// delimiter ;
source share