MySQL中的表的列设置为varchar(0)或char(0)

在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存储。

原文地址:https://www.cnblogs.com/mqfs/p/13058916.html