数据库的自动时间戳新条目(phpMyAdmin)

2022-01-13 00:00:00 timestamp mysql phpmyadmin

如果我希望数据库中的每个新条目都自动添加时间戳,是否可以将字段类型设置为时间戳"并将默认值设置为CURRENT_TIMESTAMP"?

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"?

这是正确的方法吗?

推荐答案

没错.在 SQL 代码中:

That is correct. In SQL code that would be:

CREATE TABLE `table` (
    ...
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    ...
)

相关文章