如何将MySQL日期(时间戳)字段默认为现在

时间:2019-04-02 19:41:00

标签: mysql sql

我尝试过

alter table t_granja ALTER COLUMN purchase_date TIMESTAMP DEFAULT now();

但我遇到了错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TIMESTAMP DEFAULT now()' at line 1

1 个答案:

答案 0 :(得分:0)

使用CURRENT_TIMESTAMP

ALTER TABLE t_granja 
ALTER COLUMN purchase_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP;