在MySQL中对表创建的char、varchar列选择长度时,当使用例如varchar(20)时,在5.0.3版本后表示20个字符。当使用例如varchar(0)时,在MySQL官方参考手册中是这样写的:
MySQL permits you to create a column of type CHAR(0). This is useful primarily when you must 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).
大致意思是长度为零的char或varchar表示该列用来兼容旧应用(无须更改业务代码),可以为NULL或者’’只需1bit存储。
文档更新时间: 2021-06-01 12:29 作者:阿力