views:

564

answers:

4

Hi all expert,

I would like to know what is the maximum size of varchar in SQL Server 2000. While I was googling somewhere its written 8000 characters and somewhere its written 8060 bytes. which one is correct??? Pls confirm me..

Thanks, Kumar

A: 

As far as I remember it is 8000 Chars.

For Nvarchar it is 4000.

no_one
Is 8000 char = 8000 bytes in sqL????
Kumar
+3  A: 

Varchar is 8000 and nvarchar is 4000.

Here's the varchar msdn reference:
http://msdn.microsoft.com/en-us/library/aa258242(SQL.80).aspx

Joel Coehoorn
Is 8000 char = 8000 bytes in sqL????
Kumar
@Kumar: yes, for VARCHAR, 1 character = 1 byte; for NVARCHAR, 1 character = 2 byte
marc_s
It's a little more complicated than that. Short version is that varchar and nvarchar don't use the space until you actually put data there.
Joel Coehoorn
A: 

The maximum size of varchar(max) is large (2GB or 2Gchars, I think). The maximum value you can specify for n in varchar(n) is 8000, and for nvarchar it's 4000.

erikkallen
No varchar(max) in SQL 2000
CodeByMoonlight
You're right, but then the question is void. The second part of my answer still holds
erikkallen
+1  A: 

A SQL Server data page has 8k: 8192 bytes. From this a portion is reserved for the page header, leaving 8060 bytes the maximum lnegth a single row can have. In a row, the varbinary(n), varchar(n) and nvarchar(n) types cannot exceed 8000 bytes, which means that varchar(8000) is the maximum Ascii length and nvarchar(4000) is the maximum Unicode length (since Unicode stores each character on 2 bytes).

The best explanation of all these details comes from Inside the Storage Engine: Anatomy of a page.

Remus Rusanu