Home > MySQL > MYSQL ALTER Statement for TIMESTAMP Column to Change on Update

MYSQL ALTER Statement for TIMESTAMP Column to Change on Update

January 7th, 2011

If you need to alter a TIMESTAMP column to update the column automatically when the contents of the row are changed, run the following MySQL ALTER statement against the table:

ALTER TABLE table_name CHANGE column_name column_name TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;

From now on, when any column value in a row changes, the value in the TIMESTAMP column will automatically update with the CURRENT_TIMESTAMP.

For more information on the TIMESTAMP column type in MySQL, visit http://dev.mysql.com/doc/refman/5.0/en/timestamp.html.

Categories: MySQL Tags: , ,
Comments are closed.