Max Columns in a Table

  • Hi,

      What is Max no of Columns that a table can have in sql server ?

    Thanks in advance.

     

    -Suresh

  • The max is somewhere around 254, I think. If you even approach that, it seems like it might indicate a problem with your design, though...

  • It's 1024 :

    CREATE TABLE test

    ( [1] int not null

    )

    DECLARE @I as int

    DECLARE @Exec as varchar(8000)

    PRINT '1'

    set @I = 2

    while @I < 3000

    begin

    SET @Exec = 'ALTER TABLE test ADD [' + CAST(@I AS VARCHAR(5)) + '] int null'

    EXEC (@Exec)

    IF @@ERROR 0

    SET @I = 99999

    ELSE

    BEGIN

    PRINT @I

    set @I = @I + 1

    END

    end

    DROP TABLE test

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply