edgarmtze
edgarmtze

Reputation: 25058

How many chars are available in nvarchar(MAX)

declare @string nvarchar(MAX) = ''

How many chars are available in @string?

Upvotes: 4

Views: 24822

Answers (2)

SQLMenace
SQLMenace

Reputation: 135171

nvarchar(MAX) will hold up to 2GB 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 these will be the same

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

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

Upvotes: 8

Michael Petrotta
Michael Petrotta

Reputation: 60972

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

Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for varchar are char varying or character varying.

Upvotes: 3

Related Questions