MySQL datetime 默认时间间隔

标签 mysql sql datetime

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

我试过类似的东西:

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

但是,它不起作用。

最佳答案

我认为你做不到。

MySQL Documentation指出:

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 默认时间间隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7024010/

相关文章:

php - 按 JSON 数组对 SQL 数据进行分组

python - 具有多列的日期时间的 Numpy genfromtxt 问题

python - 迭代 pandas Series 仅执行一次

java - 当使用java在MySql中的不同表中的不同列中进行插入时,如何自动更新另一个表中的列

php - MysQl 错误 : Invalid parameter number

mysql - 了解 SQL 别名

SQL Server - 重写触发器以避免基于游标的方法

sql - Presto性能调优,并行执行查询会慢很多

sql - 如何从 SQL 中的一组行构建每日历史记录?

MySQL Display All Date between range although is no record