有很多在SO和其他网站上的帖子明确说明nvarchar(max)的最大长度为2GB。然而,我在互联网和现实生活中也看到了很多困惑,认为它实际上是Unicode的8000/4000。
我想知道有哪些因素可能改变这个事实,或者可能导致某人错误地假设。
一些我已经收集到的建议/部分答案:
- Are there older SQL Server versions which did only support a maximum of 4000?
When assigning
nvarchar(max)
variable/column to a concatenation of non-max-sized components, must we convert everything tonvarchar(max)
explicitly? Here is something showcasing a strange example, where a text-returning function requires converting, whereas the N for the literal can be omitted:declare @s nvarchar(max) select @s = convert(nvarchar(max), replicate('.', 8000)) + N'Hi!' select len(@s) -- returns 8003 declare @s nvarchar(max) select @s = replicate('.', 8000) + N'Hi!' select len(@s) -- returns 4000 declare @s nvarchar(max) select @s = convert(nvarchar(max), replicate('.', 8000)) + 'Hi!' select len(@s) -- returns 8003
Are there ways to disable the functionality? Does
sp_tableoption @OptionName=large value types out of row
orOBJECTPROPERTY(id,'TableTextInRowLimit')
have anything to do with this?Clarification: My aim is not to use this functionality, but be aware of its existence, which may be indeed have been used by a higher privilege user that will prevent me from using the max size.
Any other points gladly welcome
nvarchar(max)
是 4000 的情况。曾经的情况是 在这种情况下不存在 max 关键字,您可以指定的最大数字是 4000,但这并不完全相同。此外,如果您受到此影响,那么您将面临更大的问题,因为最后一个不支持max
的版本是 SQL Server 2000,而该版本已经很久没有得到支持了。 - Damien_The_Unbelievertext/ntext/image
自从很久以前就已经被弃用了。几乎没有提到这些古老类型的参考资料,因为它们永远不应该被使用。那些参考资料说它们不应该被使用。 - Panagiotis Kanavos