更新条目而不更新时间戳 [英] Updating entry WITHOUT updating timestamp

查看:88
本文介绍了更新条目而不更新时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql表中有一个带有"ON UPDATE CURRENT_TIMESTAMP"属性的时间戳.有没有一种方法可以在特殊情况下手动禁用更新时间戳? (例如:更新条目以修改博客文章,但不重新添加日期)

I have a timestamp in a mysql table with attribute "ON UPDATE CURRENT_TIMESTAMP". Is there a way to manually disable updating the timestamp on a special occasion? (eg: updating the entry to revise a blog post, but not to re-date it)

推荐答案

有没有一种方法可以在特殊情况下手动禁用更新时间戳? (例如:更新条目以修改博客文章,但不重新添加日期)

Is there a way to manually disable updating the timestamp on a special occasion? (eg: updating the entry to revise a blog post, but not to re-date it)

听起来像您需要配置默认约束,以便仅在插入时填充列:

Sounds like you need to configure the default constraint so that it populates the column on insertion only:

DEFAULT CURRENT_TIMESTAMP

仅将其更改为意味着任何修订都不会触发时间戳值的更新. IE:如果您昨天创建了博客文章,并且今天更正了一个错字-列中的日期仍然是昨天.

Changing it to only be this means that any revisions will not trigger the timestamp value to be updated. IE: If you created the blogpost yesterday, and corrected a typo today - the date in the column would still be for yesterday.

这篇关于更新条目而不更新时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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