gpt4 book ai didi

MySQL默认值使用另一列

转载 作者:行者123 更新时间:2023-11-29 10:21:31 24 4
gpt4 key购买 nike

我有一张 table

-------------
| id | date |
-------------

现在我需要添加“周”列,那么是否可以添加类似的列

alter table `a` add column `week` INT(6) not null default DATE_FORMAT(`date`, '%Y%v')

最佳答案

上面关于使用触发器的评论是继续此操作的方法,但没有详细说明为什么不能这样做。所以,从 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 TIMESTAMP and DATETIME columns.

关于MySQL默认值使用另一列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49175936/

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