gpt4 book ai didi

mySql 日期/日期时间默认值

转载 作者:行者123 更新时间:2023-11-29 07:47:43 25 4
gpt4 key购买 nike

我有一个 Mysql 5.5 和一个包含如下列的表:

`VERSION_TS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

但我最近遇到了困难,我遇到了这个异常:

Incorrect datetime value: '1998-03-20' for column 'VERSION_TS' at row 1

尝试在表中输入值时,使用 mySql MakeDate(),输入 Date 类型的值。现在,我无法更改返回 Date 的函数,但我可以将该列更改为 Date,但随后我将丢失默认值。我尝试了一些方法,然后检查了网络,根据我在Mysql 5.5中的理解,没有办法做到这一点,但我可能是错的,所以我来这里问:

  • 有没有办法可以将列更改为日期并且仍然有默认值?
  • 此外,是否有更好的方法来解决该问题?

最佳答案

我认为documentation关于这一点非常清楚:

TIMESTAMP and DATETIME columns can be automatically initialized and updated to the current date and time (that is, the current timestamp).

因此,这不适用于DATE。但是,您可以创建一个执行您想要的操作的 View :

create view v_table as
select t.*, date(version_ts) as version_date
from table t;

关于mySql 日期/日期时间默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27271386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com