mysql - 管理两个时间戳

标签 mysql timestamp


我在一张表中有两个时间戳。
1 - timestamp01 - 这将记录用户在数据库中创建新行时的时间戳
2 - timestamp02 - 当用户更新/编辑特定行中的任何内容时,这应该记录时间戳。

我的问题是,当用户对特定行进行某些更改时,如何设置 timestamp02 来记录当前时间戳?

我使用 MySQL 作为数据库

最佳答案

此链接应该对您有帮助 https://dev.mysql.com/doc/refman/5.5/en/timestamp-initialization.html 。因此,您必须将该列标记为自动更新,以跟踪行的所有更新

timestamp02 更新时的时间戳默认为 CURRENT_TIMESTAMP CURRENT_TIMESTAMP

但是,请注意文档所说的

One TIMESTAMP column in a table can have the current timestamp as the default value for initializing the column, as the auto-update value, or both. It is not possible to have the current timestamp be the default value for one column and the auto-update value for another column.

关于mysql - 管理两个时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36687948/

相关文章:

javascript - 如何在我的代码中获取时间戳

winapi - Windows 中的 S/MIME 时间戳

mysql - MySQL 中的非聚合平均值?

php - 如何使用格式为 [col1=>[col2=>col3,col2=>col3]] 的 PDO 获取数据?

php - 限制 PHP 执行?

postgresql - 如何将通用协调时间插入 PostgreSQL TIMESTAMP 列?

jQuery:keypress() - 时间戳

php - 如何将 MySQL 时间戳转换为 d-m-yyyy

MySQL:计算列中的宽度日期

mysql - 设置 AUTO_INCREMENT 并让它在 INSERT 命令中自动赋值?