An auto-initialized column is set to the current timestamp for inserted rows that specify no value for the column.
An auto-updated column is automatically updated to the current timestamp when the value of any other column in the row is changed from its current value. An auto-updated column remains unchanged if all other columns are set to their current values. To prevent an auto-updated column from updating when other columns change, explicitly set it to its current value. To update an auto-updated column even when other columns do not change, explicitly set it to the value it should have (for example, set it to
CURRENT_TIMESTAMP).
一般表的字段datachange_lasttime 设置为timestamp类型 默认或者 OT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)。
update 时,如果除datachange_lasttime外其他字段没有改变,则datachange_lasttime并不更新,0.0和0 相当于值不变
本文详细介绍了数据库中自动初始化和自动更新的时间戳字段的工作原理。当插入新记录时,若未指定时间戳值,系统将自动设置为当前时间;而当更新记录时,即使其他字段未变化,时间戳也会自动更新到当前时间,除非显式将其设为当前时间。
1193

被折叠的 条评论
为什么被折叠?



