mysql中DATE默认值

mysql中DATE默认值,第1张

更新,在stackoverflow上找到了8.0.13版本的解决方案: 链接

经过查看官网,发现5.7版本: 链接

With one exception, the default value specified in a DEFAULT clause  must be a literal constantit 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, for TIMESTAMP and DATETIME columns, you can specify CURRENT_TIMESTAMP as the default. See Section 11.2.6, “Automatic Initialization and Updating for TIMESTAMP and DATETIME” .

创建表的时候,想为DATE类型设定默认值当前日期。发现一直报错,百度没有什么好办法。

你可以改成

publis_date

date

not

null

default

curdate()

curdate()

当前系统的时间,date

类型

sysdate()

now()

是当前系统时间并且精确到时分秒的,也就是datetime类型


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7317540.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存