Wednesday, January 21, 2015

Maximum length nvarchar(max) can accommodate in SQL 2012

The script I wrote :-

declare @str1  as nvarchar(max) = 'b'
, @count as int = 0

while @count<30
BEGIN
       set @str1 = @str1 + @str1
       set @count=@count+1
END
print len(@str1)

print @count

Results :-
1073741824
30


So in conclusion, I could say nvarchar(max) can contain till 1073741824 many characters. I haven't tried more than this. Lots of reference in Internet also says that it can contain 2GB of data and a character is 2 bytes each, which adds up to that number.

Node.JS rest api Tutorials