gpt4 book ai didi

mysql - varchar(0) 的用途是什么

转载 作者:可可西里 更新时间:2023-11-01 06:31:41 25 4
gpt4 key购买 nike

我最近遇到了一个由数据库创建脚本中的拼写错误引起的问题,数据库中的一个列被创建为 varchar(0) 而不是 varchar(20).

我原以为我会收到长度为 0 的字符串字段的错误,但我没有。 varchar(0)char(0) 的用途是什么,因为无论如何我都无法在此列中存储任何数据。

最佳答案

SQL-92 不允许这样做标准,但在 MySQL 中允许。来自MySQL manual :

MySQL permits you to create a column of type CHAR(0). This is useful primarily when you have to be compliant with old applications that depend on the existence of a column but that do not actually use its value. CHAR(0) is also quite nice when you need a column that can take only two values: A column that is defined as CHAR(0) NULL occupies only one bit and can take only the values NULL and '' (the empty string).

关于mysql - varchar(0) 的用途是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21555485/

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