There are multiple posts on both SO and other sites which clearly state that the maximum length of nvarchar(max)
is 2GB. However, I see also much confusion in both internet and real life that it actually is 8000/4000 in Unicode.
I would like to know what things could change that fact, or maybe lead someone to falsely assume so.
Some suggestions/partial answers I've already gathered:
- 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