简体   繁体   English

nvarchar(MAX)将保留的最大字符数是多少?

[英]What is the maximum number of characters that nvarchar(MAX) will hold?

I'm new to the concept nvarchar(MAX) . 我是概念nvarchar(MAX)新手。 How many characters will it hold? 它会包含多少个字符?

Max. 最大。 capacity is 2 gigabytes of space - so you're looking at just over 1 billion 2-byte characters that will fit into a NVARCHAR(MAX) field. 容量是2千兆字节的空间 - 因此您正在查看超过10亿个2字节字符,这些字符将适合NVARCHAR(MAX)字段。

Using the other answer's more detailed numbers, you should be able to store 使用其他答案更详细的数字,您应该能够存储

(2 ^ 31 - 1 - 2) / 2 = 1'073'741'822 double-byte characters

1 billion, 73 million, 741 thousand and 822 characters to be precise

in your NVARCHAR(MAX) column (unfortunately, that last half character is wasted...) 在您的NVARCHAR(MAX)列中(不幸的是,后半个字符被浪费了......)

Update: as @MartinMulder pointed out: any variable length character column also has a 2 byte overhead for storing the actual length - so I needed to subtract two more bytes from the 2 ^ 31 - 1 length I had previously stipulated - thus you can store 1 Unicode character less than I had claimed before. 更新:正如@MartinMulder所指出的:任何可变长度字符列也有2字节的开销用于存储实际长度 - 所以我需要从我之前规定的2 ^ 31 - 1 31-1长度中减去两个以上的字节 - 因此你可以存储1个Unicode字符比我之前声称的少。

From char and varchar (Transact-SQL) 来自char和varchar(Transact-SQL)

varchar [ ( n | max ) ] varchar [(n | max)]

Variable-length, non-Unicode character data. 可变长度的非Unicode字符数据。 n can be a value from 1 through 8,000. n可以是1到8,000之间的值。 max indicates that the maximum storage size is 2^31-1 bytes. max表示最大存储大小为2 ^ 31-1个字节。 The storage size is the actual length of data entered + 2 bytes. 存储大小是输入的实际数据长度+ 2个字节。 The data entered can be 0 characters in length. 输入的数据长度可以是0个字符。 The ISO synonyms for varchar are char varying or character varying. varchar的ISO同义词是char变化或字符变化。

2^31-1 bytes. 2 ^ 31-1个字节。 So, a little less than 2^31-1 characters for varchar(max) and half that for nvarchar(max). 因此,varchar(max)的字符少于2 ^ 31-1个字符,nvarchar(max)的字符的一半。

nchar and nvarchar nchar和nvarchar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM