MySQL: record update WITHOUT time update

I have a timestamp in the mysql table with the attribute "ON UPDATE CURRENT_TIMESTAMP". Is there a way to manually turn off timestamp updates for a special case? (for example: update a post to revise a blog post but not rewrite it)

+67
sql mysql timestamp
May 16 '10 at 18:08
source share
5 answers

Is there a way to manually turn off timestamp updates on a special occasion? (for example: update a post to revise a blog post but not rewrite it)

It looks like you need to set a default constraint so that it fills the column only when pasting:

DEFAULT CURRENT_TIMESTAMP 

Changing this only means that any changes will not cause the timestamp value to be updated. IE: If you created a blog yesterday and corrected a typo today - the date in the column will still be the same as yesterday.

+45
May 16 '10 at 18:21
source share

You can manually set the column value to the current value in the update command:

 UPDATE table SET x=y, timestampColumn=timestampColumn WHERE a=b; 

If you do not set a value in the query, it will be updated to the current timestamp according to the table definition.

+128
May 16 '10 at 18:16
source share

To automatically update your table / timestamp:

 ALTER TABLE myTable CHANGE myTimestampColumn myTimestampColumn TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; 

To do this is not an automatic update:

 ALTER TABLE myTable CHANGE myTimestampColumn myTimestampColumn TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; 

NOTE. The parameter "default current_timestamp" simply sets it to the current stamp by default, since the field is not-null. You can delete both non-zero and default if you want.

+20
Jul 29 '15 at 5:51 on
source share

do not use timestamps, but track the time manually.

if you really want to update the record and not update its timestamp:

 UPDATE `table` SET `timestamp` = `timestamp`, `col` = 'new data' …; 
+9
May 16 '10 at 18:14
source share

If you change the timestemp when updating, you should take into account that if the value has been updated but not changed (the save value has been updated), then it will not update "on update Current_timestemp", and in this situation you must set timestemp manually

SET LastUpdatedDate=NOW() WHERE

The idea came from here: Click on a MYSQL record to update the TIMESTAMP field

0
Oct 27 '15 at 13:16
source share



All Articles