从 mysql8 开始,这是合法的:
CREATE TABLE t (d DATETIME DEFAULT CURRENT_TIMESTAMP);
这是合法的:
CREATE TABLE t (d DATE DEFAULT (CURRENT_DATE));
那么为什么这是非法的?
CREATE TABLE t (d DATE DEFAULT CURRENT_DATE);
导致
Error in query (1064): Syntax error near 'CURRENT_DATE)' at line 1
最佳答案
这很可能是您在问题中所指的内容:
The default value specified in a DEFAULT clause can be a literal constant or an expression. With one exception, enclose expression default values within parentheses to distinguish them from literal constant default values.
[...]
The exception is that, for TIMESTAMP and DATETIME columns, you can specify the CURRENT_TIMESTAMP function as the default, without enclosing parentheses.
关于mysql - 在 mysql8 中,为什么 DATE DEFAULT CURRENT_DATE 需要在 CURRENT_DATE 周围加括号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69880064/