`

mysql char varchar

 
阅读更多

 摘自:http://dev.mysql.com/doc/refman/5.6/en/char.html

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. 

 

 

表的列数限制:

There is a hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact limit depends on several interacting factors.

 表的行大小限制:

Every table (regardless of storage engine) has a maximum row size of 65,535 bytes. Storage engines may place additional constraints on this limit, reducing the effective maximum row size. 

 是说一行所有列长加和:

The maximum row size constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size. For example, utf8 characters require up to three bytes per character, so for a CHAR(255) CHARACTER SET utf8 column, the server must allocate 255 × 3 = 765 bytes per value. Consequently, a table cannot contain more than 65,535 / 765 = 85 such columns. 

 

For VARCHAR columns, trailing spaces in excess of the column length are truncated prior to insertion and a warning is generated, regardless of the SQL mode in use. For CHAR columns, truncation of excess trailing spaces from inserted values is performed silently regardless of the SQL mode.

VARCHAR values are not padded when they are stored. Trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL.

The following table illustrates the differences between CHAR and VARCHAR by showing the result of storing various string values into CHAR(4) and VARCHAR(4) columns (assuming that the column uses a single-byte character set such as latin1).

Value CHAR(4) Storage Required VARCHAR(4) Storage Required
'' '    ' 4 bytes '' 1 byte
'ab' 'ab  ' 4 bytes 'ab' 3 bytes
'abcd' 'abcd' 4 bytes 'abcd' 5 bytes
'abcdefgh' 'abcd' 4 bytes 'abcd' 5 bytes
分享到:
评论
1 楼 nicegege 2016-10-10  
    受益匪浅

相关推荐

    char和varchar在mysql中的效率怎样.docx

    char和varchar在mysql中的效率怎样.docx

    对比MySQL中int、char以及varchar的性能

    在本篇文章中我们给大家分享了关于MySQL中int、char以及varchar的性能对比的相关内容,有兴趣的朋友们学习下。

    Mysql中varchar长度设置方法

    主要介绍了Mysql中varchar长度设置方法的相关资料,本文还给大家带来了valar类型的变化及char()和varchar()的区别介绍,非常不错,具有参考借鉴价值,需要的朋友可以参考下

    MySQL CHAR和VARCHAR存储、读取时的差别

    你真的知道CHAR和VARCHAR类型在存储和读取时的区别吗? 还是先抛几条结论吧: 1、存储的时候,CHAR总是会补足空格后再存储,不管用户插入数据时尾部有没有包含空格。 2、存储的时候,VARCHAR不会先补足空格后再存储...

    MYSQL中 char 和 varchar的区别

    主要介绍了MYSQL中 char 和 varchar的区别,帮助大家更好的理解和使用MySQL数据库,感兴趣的朋友可以了解下

    MySQL中VARCHAR与CHAR格式数据的区别

    char是一种固定长度的类型,varchar则是一种可变长度的类型,那么他们具体使用过程中有什么区别吗

    MySQL数据库char与varchar的区别分析及使用建议

    在MySQL数据库中,用的最多的字符型数据类型就是Varchar和Char.。这两种数据类型虽然都是用来存放字符型数据,但是无论从结构还是 从数据的保存方式来看,两者相差很大。而且其具体的实现方式,还依赖与存储引擎。我...

    mysql中char与varchar的区别分析

    char与varchar的区别 char (13)长度固定, 如’www.jb51.net’ 存储需要空间 12个字符 varchar(13) 可变长 如’www.jb51.net’ 需要存储空间 13字符, 从上面可以看得出来char 长度是固定的,不管你存储的数据是多少...

    浅析Oracle中char和varchar2的区别 电脑资料.docx

    浅析Oracle中char和varchar2的区别 电脑资料.docx

    MySQL中CHAR和VARCHAR类型演变和详解

    MySQL数据库的varchar类型在5.0.3以下的版本中的最大长度限制为255,其数据范围可以是0~255

    MySQL中字段类型char、varchar和text的区别

    在MySQL中,char、varchar和text类型的字段都可以用来存储字符类型的数据,char、varchar都可以指定最大的字符长度,但text不可以。 它们的存储方式和数据的检索方式也都不一样。 数据的检索效率是:char > varchar ...

    MySQL中把varchar类型转为date类型方法详解

    如下表: 先使用str_to_date函数,将其varchar类型转为日期类型,然后从小到大排序 ...SELECT to_char(to_date(m.ma_datetime,'yyyy-MM-dd hh24:mi:ss'), 'yyyyMMdd') FROM my_task m; m.ma_datet

    mysql varchar类型求和实例操作

    有的小伙伴在学习数据库的时候,创建表结构的时候不小心把某字段设置成了varchar但是在统计求和的时候就傻眼了,接下来跟着小编学习一下,不用改该列数据类型也能求和的方法吧! 1、打开 数据库连接客户端Navicat ...

Global site tag (gtag.js) - Google Analytics