Auto TimeStamp new entry to DB (phpMyAdmin)

2020-02-24 12:48发布

If I want each new entry into my db to be automatically timestamped, would I set the Field Type to "timestamp" and have the Default value set to "CURRENT_TIMESTAMP"?

Is this the correct method?

2条回答
萌系小妹纸
2楼-- · 2020-02-24 13:10

Yes, this method is correct:

 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
查看更多
孤傲高冷的网名
3楼-- · 2020-02-24 13:29

That is correct. In SQL code that would be:

CREATE TABLE `table` (
    ...
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    ...
)
查看更多
登录 后发表回答