CURRENT_DATE / CURDATE()不能作为默认的DATE值 [英] CURRENT_DATE/CURDATE() not working as default DATE value

查看:1548
本文介绍了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 as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column

http ://dev.mysql.com/doc/refman/5.5/en/create-table.html

这篇关于CURRENT_DATE / CURDATE()不能作为默认的DATE值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆