个人觉得存成char(12),优于varchar(12)

Posted rsapaper

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了个人觉得存成char(12),优于varchar(12)相关的知识,希望对你有一定的参考价值。

w

延展一点:0----(还是上边的url),varchar(10)则数据库的存储1-11bytes,而不是0-10bytes;varchar(256)则为2-258bytes; 1----如果待入库string长度为0-12(相对较小,或者说推测或历史记录中大概率为11,12),个人觉得存成char(12),优于varchar(12)(最初设计为或修改为);2-对于入库的string长度过滤和未过滤下的db自处理,是另外的话题了;

https://dev.mysql.com/doc/refman/5.7/en/char.html 

         Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 65,535. The effective maximum length of a VARCHAR is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used. See Section C.10.4, “Limits on Table Column Count and Row Size”.

In contrast to CHAR, VARCHAR values are stored as a 1-byte or 2-byte length prefix plus data. The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes.       

 

以上是关于个人觉得存成char(12),优于varchar(12)的主要内容,如果未能解决你的问题,请参考以下文章

char和varchar2的异同点

6-12 varchar和char 枚举类型enum 集合set

实体框架代码优先 MaxLength 和 FixedLegth(char 与 varchar)

关于 char varchar 和 tinyint 的问题

Char和VarChar有啥区别[重复]

VC怎样把文件存成BMP格式