SQL Server varchar(最大)中的字符数?

时间:2022-03-26 12:34:07

Microsoft's documentation on the varchar(max) data type:

微软关于varchar(max)数据类型的文档:

"Variable-length, non-Unicode string data. . . max indicates that the maximum storage size is 2^31-1 bytes (2 GB). The storage size is the actual length of the data entered + 2 bytes"

“可变长度、非unicode字符串数据……”马克斯表示最大存储大小是2 ^还有字节(2 GB)。存储大小是输入数据的实际长度+ 2字节

http://technet.microsoft.com/en-us/library/ms176089.aspx

http://technet.microsoft.com/en-us/library/ms176089.aspx

I thought 2^31 bytes = 2 GB, not that 2^31-1 bytes = 2 GB. Am I wrong on this point?

我认为2 ^ 31字节数= 2 GB,不是2 ^还有字节数= 2 GB。在这一点上我错了吗?

Two of the bytes are reserved for column overhead, so the question becomes:

其中两个字节为列开销预留,因此问题变成:

How many characters will the data type store?
a) 2^31-3 = 2,147,483,645 bytes = 2,147,483,645 Characters
b) 2^31-2 = 2,147,483,646 bytes = 2,147,483,646 Characters

数据类型将存储多少字符?2)^ 31-3 = 2147483645字节= 2147483645个字符b)2 ^ 31-2 = 2147483646字节= 2147483646个字符

1 个解决方案

#1


2  

The number 2^31-1 is 0x7fffffff in hex. It's the largest possible positive 32-bit number on a twos-compliment machine (like the x86 and just about everything else).

数量2 ^还有是0 x7fffffff十六进制。它是一个双恭维机器上最大的正32位数字(像x86和几乎所有其他东西)。

The documentation is telling you that this is the maximum storage size, which has to hold the length of the data plus 2 bytes. This means that the maximum data size is 2^31-1-2, or 2,147,483,645 (0x7FFFFFFD).

文档告诉您,这是最大的存储大小,它必须包含数据的长度加上2个字节。这意味着最大数据大小是2 ^ 31-1-2,或2147483645(0 x7ffffffd)。

#1


2  

The number 2^31-1 is 0x7fffffff in hex. It's the largest possible positive 32-bit number on a twos-compliment machine (like the x86 and just about everything else).

数量2 ^还有是0 x7fffffff十六进制。它是一个双恭维机器上最大的正32位数字(像x86和几乎所有其他东西)。

The documentation is telling you that this is the maximum storage size, which has to hold the length of the data plus 2 bytes. This means that the maximum data size is 2^31-1-2, or 2,147,483,645 (0x7FFFFFFD).

文档告诉您,这是最大的存储大小,它必须包含数据的长度加上2个字节。这意味着最大数据大小是2 ^ 31-1-2,或2147483645(0 x7ffffffd)。