MySQL SQL varchar 字符限制
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23840487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL varchar character limit
提问by EasyBB
I have read different explanations of varchar
and so far I've gotten this:
我已经阅读了不同的解释,varchar
到目前为止我已经得到了这个:
CHAR( ) fixed from 0 to 255 characters long
VARCHAR( ) variable from 0 to 255 characters long
TINYTEXT maximum length of 255 characters
TEXT maximum length of 65535 characters
BLOB maximum length of 65535 characters
MEDIUMTEXT maximum length of 16777215 characters
MEDIUMBLOB maximum length of 16777215 characters
LONGTEXT maximum length of 4294967295 characters
LONGBLOB maximum length of 4294967295 characters
and then this
然后这个
char(n)variables store fixed-length character strings conisisting of exactly n characters (and, therefore, n bytes). They are limited to 8,000 characters in size.
nchar(n)variables store fixed-length Unicode character strings conisisting of exactly n characters (and, therefore, 2*n bytes). They are limited to 4,000 characters in size.
varchar(n)variables store non-fixed length character strings consisting of approximately n characters. They consume l+2 bytes of space, where l is the actual length of the string. They are limited to 8,000 characters in size.
- nvarchar(n)variables store non-fixed length Unicode character strings consisting of approximately n characters. They consume 2*l+2 bytes of space, where l is the actual length of the string. They are limited to 4,000 characters in size.
- varchar(max)variables store non-fixed length character strings consisting of up to 1,073,741,824 characters. They consume l+2 bytes of space, where l is the actual length of the string.
- nvarchar(max)variables store non-fixed length Unicode character strings consisting of up to 536,870,912 characters. They consume l*2+2 bytes of space, where l is the actual length of the string.
- textand ntextvariables store up to 2GB of text data (ANSI and Unicode, respectively), but can not be used in many text operations. Therefore, they are usually only used to support legacy applications and have been replaced by the varchar(max) and nvarchar(max) data types.
char(n)变量存储由恰好 n 个字符(因此,n 个字节)组成的固定长度字符串。它们的大小限制为 8,000 个字符。
nchar(n)变量存储由恰好 n 个字符(因此,2*n 个字节)组成的固定长度的 Unicode 字符串。它们的大小限制为 4,000 个字符。
varchar(n)变量存储由大约 n 个字符组成的非固定长度字符串。它们消耗 l+2 字节的空间,其中 l 是字符串的实际长度。它们的大小限制为 8,000 个字符。
- nvarchar(n)变量存储由大约 n 个字符组成的非固定长度的 Unicode 字符串。它们消耗 2*l+2 字节的空间,其中 l 是字符串的实际长度。它们的大小限制为 4,000 个字符。
- varchar(max)变量存储由最多 1,073,741,824 个字符组成的非固定长度字符串。它们消耗 l+2 字节的空间,其中 l 是字符串的实际长度。
- nvarchar(max)变量存储由最多 536,870,912 个字符组成的非固定长度的 Unicode 字符串。它们消耗 l*2+2 字节的空间,其中 l 是字符串的实际长度。
- text和ntext变量最多可存储 2GB 的文本数据(分别为 ANSI 和 Unicode),但不能用于许多文本操作。因此,它们通常仅用于支持遗留应用程序,并已被 varchar(max) 和 nvarchar(max) 数据类型取代。
So really what is the character max on varchar
? Reason I am wondering is I am starting a simple little CMS
and I don't want my SQL DB to overloaded with weight and as you can see for example
那么到底什么是最大的字符varchar
呢?我想知道的原因是我开始了一个简单的小事CMS
,我不希望我的 SQL DB 因重量而过载,例如您可以看到
nvarchar(max)[length] * 2 + 2
nvarchar being 100,000 * 2 + 2 = 200,002 bytes (what is + 2 is it literal?)
Also I've read that varchar(8,000)
is better than varchar(max)
so what would you suggest the type that I use for a variably changing character length, especially for content.
另外,我读过这varchar(8,000)
比varchar(max)
你建议的类型更好,我用于可变变化的字符长度,尤其是内容。
回答by mukunda
http://dev.mysql.com/doc/refman/5.0/en/char.html
http://dev.mysql.com/doc/refman/5.0/en/char.html
The length can be specified as a value from 0 to 255 before MySQL 5.0.3,
and 0 to 65,535 in 5.0.3 and later versions.
I don't think your second paste is talking about MySQL.
我不认为你的第二贴是在谈论 MySQL。