Search code examples
mysqlalter

on insert current_timestamp in mysql


I need to alter a column with timestamp datatype. The thing is when record is inserted the current time stamp should be inserted in that column. I know there is ON UPDATE CURRENT_TIMESTAMP but for insertion i can't find a way.


Solution

  • What you're looking for is the DEFAULT keyword.

    ALTER TABLE yourTable MODIFY COLUMN yourColumn timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;