开发者

MYSQL timestamp column auto update even if there is no changes?

开发者 https://www.devze.com 2023-04-11 20:14 出处:网络
I have a column update_date in a table and type is timestamp. I set the deault value by using phpmyadmin drop down menu to CURRENT_TIMESTAM开发者_如何学编程P. But later when ever I run sql UPDATE x SE

I have a column update_date in a table and type is timestamp. I set the deault value by using phpmyadmin drop down menu to CURRENT_TIMESTAM开发者_如何学编程P. But later when ever I run sql UPDATE x SET ... it updates the timestamp column if only there is a changes in any of the columns. What I would like to achieve is that whether there is a change or not set the current time everytime the update sql runs. Is there any way of doing it in the mysql or I need to set the update_date explicitly every time the update is called?

Thank you


You need to explicitly update the column. From the MySQL manual, TIMESTAMP properties:

The auto-update TIMESTAMP column, if there is one, is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. If all other columns are set to their current values, the TIMESTAMP column does not change. Automatic updating does not apply if the TIMESTAMP column is explicitly assigned a value other than NULL.

Emphasis mine.

0

精彩评论

暂无评论...
验证码 换一张
取 消