Home Forums SQL Server 2005 Development Difference between varchar(max) and varchar(8000) RE: Difference between varchar(max) and varchar(8000)

  • Jeff Moden (2/2/2009)


    charlesz (2/2/2009)


    Second, NVarchar(MAX) and Varchar(MAX) can only hold up to 65535 bytes ( The number posted by Gail Shaw was wrong).

    Any bets on that?

    DECLARE @test-2 VARCHAR(MAX),

    @String VARCHAR(MAX)

    SELECT @test-2 = '',

    @String = '1234567890'

    ;WITH

    cteTally AS

    (--==== Create a Tally CTE from 1 to 10,000

    SELECT TOP (10000)

    ROW_NUMBER() OVER (ORDER BY t1.ID) AS N

    FROM Master.sys.SysColumns t1

    CROSS JOIN Master.sys.SysColumns t2

    )

    SELECT @test-2 = @test-2 + '1234567890'

    FROM cteTally

    SELECT LEN(@Test)

    I have to ask... where did you get such an idea? I'd like to know so I can go straighten them out. 😉

    And now, direct from Book Online for viewing pleasure!

    varchar [ ( n | max ) ]

    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 SQL-2003 synonyms for varchar are char varying or character varying.

    And

    nvarchar [ ( n | max ) ]

    Variable-length Unicode character data. n can be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The SQL-2003 synonyms for nvarchar are national char varying and national character varying.

    So, I must agree with Jeff, who and where did you here that so that they may be properly corrected. I see pork chops in someones future!