CURRENT_DATE/CURDATE() not working as default DATE value(CURRENT_DATE/CURDATE() 不作为默认 DATE 值工作)
问题描述
这里很直接的问题,我认为这应该有效,但它没有.为什么不呢?
Pretty straight forward question here, I think this should work but it doesn't. Why doesn't it?
CREATE TABLE INVOICE(
INVOICEDATE DATE NOT NULL DEFAULT CURRENT_DATE
)
推荐答案
它不起作用,因为它不受支持
It doesn't work because it's not supported
DEFAULT
子句指定列的默认值.除了一个例外,默认值必须是一个常量;它不能是函数或表达式.这意味着,例如,您不能将日期列的默认值设置为诸如 NOW()
或 CURRENT_DATE
之类的函数的值.例外是您可以将 CURRENT_TIMESTAMP
指定为 TIMESTAMP
列的默认值
The
DEFAULT
clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such asNOW()
orCURRENT_DATE
. The exception is that you can specifyCURRENT_TIMESTAMP
as the default for aTIMESTAMP
column
http://dev.mysql.com/doc/refman/5.5/en/create-table.html
这篇关于CURRENT_DATE/CURDATE() 不作为默认 DATE 值工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CURRENT_DATE/CURDATE() 不作为默认 DATE 值工作


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01