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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM