【发布时间】:2015-04-22 03:49:58
【问题描述】:
我用的是mysql,所有表都有四个字段,
created_by varchar(128)
created_on timestamp default current_timestamp
updated_by varchar(128)
updated_on timestamp default current_timestamp
我读过关于堆栈溢出的不同答案,每次对表行执行某些操作时,默认值为current_timestamp 的字段会自动更新。但是我想created_on在新记录更新时自动插入current_timestamp,并且当这条记录在一段时间后更新时,只有updated_by字段自动更新为current_timestamp而不是created_by。
【问题讨论】:
-
RTM,在 5.6 之前,您只能有一个带有
DEFAULT CURRENT_TIMESTAMP的字段。不知道为什么,但您要么必须手动设置updated或created值,要么创建一个触发器(即,IMO,丑陋)。
标签: php mysql datetime timestamp