How many characters are available in nvarchar (MAX)

declare @string nvarchar(MAX) = ''

How many characters are available in @string?

+3
source share
2 answers

nvarchar (MAX) will contain up to 2 GB, which is about 1 billion characters, since it is unicode

in your case it is 0

also take a look at this, datalength counts storage, len counts characters, for varchar they will be the same

declare @string nvarchar(MAX) = ''
select datalength(@string), LEN(@string)
GO

declare @string nvarchar(MAX) = '1'
select datalength(@string), LEN(@string)
+6
source

You have about two billion bytes of Unicode characters to play. From the MSDN documentation for char and varchar :

, . n 1 8000. max , 2 ^ 31-1 . - + 2 . 0 . ISO varchar: char .

+3

All Articles