Wednesday, June 10, 2015

MySQL data type timestamp auto-initialized and auto-updated



When we set MySQL data type timestamp, the default is auto-initialized. It is set to the current timestamp for inserted rows. This can be used in a column such as creation date. In PHPMyAdmin,
the attribute is empty.

When we set the attributes "on update current_timestamp" and type 'timestamp' in PHPMyAdmin,  the column is auto-updated. It is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. The column remains unchanged if all other columns are set to their current values. This can be used in a column such as modification date.

MySQL:
ALTER TABLE `max_term_default_ttr_lut` ADD `CreateDate` TIMESTAMP NULL DEFAULT NULL ,
ADD `ModificationDate` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP NULL DEFAULT NULL ,
ADD `creator` VARCHAR( 45 ) NULL DEFAULT NULL ,
ADD `modifier` VARCHAR( 45 ) NULL DEFAULT NULL ;

No comments:

Post a Comment