即使没有更改,MYSQL时间戳列也会自动更新? [英] MYSQL timestamp column auto update even if there is no changes?

查看:608
本文介绍了即使没有更改,MYSQL时间戳列也会自动更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中有一列update_date,类型为时间戳.我通过使用phpmyadmin下拉菜单将default值设置为CURRENT_TIMESTAMP.但是以后我运行sql UPDATE x SET时... 如果任何列中只有更改,它将更新timestamp列.我想实现的是,每次运行更新sql时是否更改当前时间.在mysql中有什么办法吗?还是需要在每次调用更新时显式设置update_date?

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_TIMESTAMP. 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?

谢谢

推荐答案

您需要显式更新该列.在MySQL手册中, TIMESTAMP属性:

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

如果行中的任何其他列的值都从其当前值更改,则自动更新TIMESTAMP列(如果有的话)会自动更新为当前时间戳. 如果所有其他列均设置为其当前值,则TIMESTAMP列不会更改.如果TIMESTAMP列被显式分配了非NULL的值,则自动更新不适用.

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.

强调我的.

这篇关于即使没有更改,MYSQL时间戳列也会自动更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆