MySQL datetime默认时间间隔 [英] MySQL datetime default time with interval

查看:161
本文介绍了MySQL datetime默认时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以添加到NOW(),10分钟的默认时间?

Is it possible to add to a default time with NOW(), 10 minutes?

我已经尝试过这样的事情:

I've tried something like that:

CREATE TABLE `table1` (
    `date` DATETIME NOT NULL DEFAULT DATE_ADD(NOW(), INTERVAL 10 MINUTE)
);  

但是,它不起作用。

推荐答案

我不认为你可以做到这一点。

I dont think you can do this.

MySQL文档指出:


数据类型规范中的DEFAULT值子句表示
默认值列的值。除了一个例外,默认值必须为
为常数;它不能是一个函数或表达式。这意味着,例如,
,您不能将日期列的默认值设置为
一个函数的值,例如NOW()或CURRENT_DATE。
的例外是您可以指定CURRENT_TIMESTAMP作为
TIMESTAMP列的默认值。

The DEFAULT value clause in a data type specification indicates 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

这篇关于MySQL datetime默认时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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