gpt4 book ai didi

mysql - 如何设置mysql默认值NONE

转载 作者:行者123 更新时间:2023-11-29 01:14:06 25 4
gpt4 key购买 nike

我正在使用一个包含列的表“media_content”

id varchar(50) NOT NULL,
shorttitle varchar(200) DEFAULT NULL,
sourceimage blob

后来我将 sourceimage 列修改为默认值 NULL

ALTER TABLE media_content
MODIFY COLUMN sourceimage VARCHAR(250) DEFAULT NULL;

现在我想让 sourceimage 列默认为 NONE,是否可以这样做?

最佳答案

您可以将(字符串类型列的)默认值指定为字符串常量,例如 'NONE',但请注意,这样的值确实具有非常不同的含义为 NULL(表示根本没有值)。

根据 Working with NULL Values 记录:

The NULL value can be surprising until you get used to it. Conceptually, NULL means “a missing unknown value” and it is treated somewhat differently from other values.

[ deletia ]

A common error when working with NULL is to assume that it is not possible to insert a zero or an empty string into a column defined as NOT NULL, but this is not the case. These are in fact values, whereas NULL means “not having a value.”

如果您只是想以其他方式向您的用户显示 NULL 值,您应该在应用程序的表示层处理它。

关于mysql - 如何设置mysql默认值NONE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12949575/

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