如果我希望数据库中的每个新条目都自动添加时间戳,我是否可以将字段类型设置为"timestamp“,并将默认值设置为"CURRENT_TIMESTAMP"?
这是正确的方法吗?
发布于 2010-09-01 14:20:37
这是正确的。在SQL代码中,这将是:
CREATE TABLE `table` (
...
`date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
...
)
发布于 2010-09-01 14:20:55
是的,这种方法是正确的:
create table t(Id int, ts timestamp default current_timestamp)
insert into t(Id) values (1)
select * from t
1;2010-09-01 09:20:09:000
https://stackoverflow.com/questions/3615471
复制相似问题