SQL nvarchar(MAX) 中有多少字符可用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5254750/
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
How many chars are available in nvarchar(MAX)
提问by cMinor
declare @string nvarchar(MAX) = ''
How many chars are available in @string?
@string 中有多少个可用的字符?
回答by SQLMenace
nvarchar(MAX) will hold up to 2GB which is about 1 billion characters since it is unicode
nvarchar(MAX) 最多可容纳 2GB,大约 10 亿个字符,因为它是 unicode
in your case it is 0
在你的情况下它是 0
also take a look at this, datalength counts storage, len counts characters, for varchar these will be the same
也看看这个,datalength 计算存储,len 计算字符,对于 varchar 这些将是相同的
declare @string nvarchar(MAX) = ''
select datalength(@string), LEN(@string)
GO
declare @string nvarchar(MAX) = '1'
select datalength(@string), LEN(@string)
回答by Michael Petrotta
You have about two billion bytes worth of Unicode characters to play with. From the MSDN documentation for char and varchar:
您可以使用大约 20 亿字节的 Unicode 字符。来自char 和 varchar 的 MSDN 文档:
Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for varchar are char varying or character varying.
可变长度的非 Unicode 字符数据。n 可以是 1 到 8,000 之间的值。max 表示最大存储大小为 2^31-1 字节。存储大小为输入数据的实际长度+2 个字节。输入的数据长度可以为 0 个字符。varchar 的 ISO 同义词是 char 变化或字符变化。