on insert current_timestamp in mysql

Rock 'em picture Rock 'em · Jan 24, 2013 · Viewed 13.2k times · Source

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.

Answer

fancyPants picture fancyPants · Jan 24, 2013

What you're looking for is the DEFAULT keyword.

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