CURRENT_TIMESTAMP on update within mysql

Posted 3 years ago

To set the current timestamp on a column within MySQL, simply create a column with the “TIMESTAMP” datatype. Then you need to ensure the default is as below


CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

You can run the following query to alter your table.


ALTER TABLE `table.name` CHANGE `column.name` `column.name` TIMESTAMP 
DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;