THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Kalen Delaney

Geek City: Too Many Indexes!

I wrote about "Too Many Columns" last September, and along with changes in SQL Server 2008 that allow lots of columns, there is also the ability to create more than the old maximum of 249 nonclustered indexes on a table. I knew this fact, but somehow I overlooked it when updating the chapter on table structures in my new book. My omission also got past all the editors, and I just realized my mistake when reviewing the Indexes chapter, which was being updated for SQL 2008 by Kimberly Tripp. 

I found that Books Online has not been completely updated (and I have filed a doc bug on this already). This page still says the limit is 249  nonclustered indexes per table:

However, the page for CREATE TABLE at does say:

Each table can contain a maximum of 999 nonclustered indexes, and 1 clustered index. These include the indexes generated to support any PRIMARY KEY and UNIQUE constraints defined for the table.

You can take my script to create a table with lots of columns, and edit it to create a UNIQUE constraint on every column.

DECLARE @create varchar(max);
DECLARE @tabname sysname;
DECLARE @numcols int;
DECLARE @col int;
SELECT @numcols = 900;
SELECT @tabname = 'wide' + CONVERT(varchar, @numcols);

SELECT @create = 'CREATE TABLE ' + @tabname +
      ' (ID int IDENTITY, ';

SELECT @col = 1;
WHILE @col < @numcols BEGIN
    IF (@col % 3) = 0
       SELECT @create = @create + 'col' + CONVERT(varchar, @col) +
           ' int UNIQUE,';
    IF (@col % 3) = 1    
            SELECT @create = @create + 'col' + CONVERT(varchar, @col) +
             ' char(5) UNIQUE,';
     IF (@col % 3) = 2     
            SELECT @create = @create + 'col' + CONVERT(varchar, @col) +
             ' varchar(25) UNIQUE,';
SELECT @col = @col + 1;
SELECT @create = @create + 'col' + CONVERT(varchar, @col) +
           ' int default 0);'
PRINT @create 
EXECUTE (@create)

After the table is created, you can examine sys.indexes:

SELECT name, index_id, type_desc
FROM sys.indexes
WHERE object_id = object_id('wide900');

You'll definitely see more than 249 indexes! In addition, you might note that there is a gap in the index_id values. The values 251 - 255 are not used, and this is for backward compatibility. In much older versions, index_id (or indid) 255 was reserved for the LOB data belonging to a table, and the values from 251 - 254 were reserved. So that range is still not used. But you can see that I have index_id values from 256 - 905 in this table.

So, thanks Kim~

One more place that Books Online could use a little tweaking is in the section on Programmability Enhancements:

The section on "Wide Tables" seems to imply that you need to have an XML column set in order to get 1000 indexes. It doesn't actually say that, so it's not really a bug, but it does seem to imply it:

Wide tables are tables that contain one or more column sets. A wide table can contain up to 30000 columns, 1000 indexes, and 30000 statistics.

Because you can only reach the 30000 column limit with a wide table, it seems to imply that the 1000 index limit is only for wide tables. But as my script shows, it is not. You can have up to 1024 columns in a non-wide table, and you can now have indexes on every one of those columns.

But do you want that many? That's for another post, another time...

Have fun!


Published Sunday, January 18, 2009 1:37 PM by Kalen Delaney

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



James Luetkehoelter said:

Kalen (and Kim by proxy):

Wouldn't beat someone up if you found someone putting 249 indexes on a table to start with, much less MORE than that? Even if it is a reporting database, what would someone need with those? Covering indexes for every query used? And in the mean time the query optimizer needs to go on Prozac trying to juggle all of that?

Ok, I exaggerate, but am I wrong? If someone needs more that 249 indices, there's something very wrong with the database structure and or query design....

January 20, 2009 11:21 AM

aaaa said:

mt0417 mt0417

April 16, 2018 9:01 PM

shenyuhang said:


June 1, 2018 7:04 PM

dongdong8 said:



June 29, 2018 2:49 AM

linying123 said:



July 16, 2018 8:34 PM

dongdong8 said:



July 23, 2018 11:29 PM

shenyuhang said:


July 23, 2018 11:37 PM

obat diabetes said:

August 1, 2018 11:29 PM

obat bronkitis anak secara alami said:

August 7, 2018 7:56 PM

yaoxuemei said:


August 15, 2018 2:07 AM

qqq said:

August 16, 2018 12:16 AM

chenjinyan said:


August 22, 2018 11:06 PM

shenyuhang said:


August 23, 2018 10:19 PM

obat herbal koresterol terbaik said:

August 23, 2018 11:03 PM

obat usus buntu alami tanpa operasi said:

August 24, 2018 12:29 AM

obat benjolan di tubuh said:

August 30, 2018 7:45 PM

obat wasir said:

September 4, 2018 8:31 PM

obat katarak said:

September 17, 2018 1:53 AM

obat maag said:

September 17, 2018 7:16 PM

obat limfoma said:


September 23, 2018 6:55 PM

kakakaoo said:

October 8, 2018 2:29 AM

chenjinyan said:



October 9, 2018 6:49 PM

kakakaoo said:


November 8, 2018 2:07 AM

qqq said:


March 27, 2019 12:59 AM

Leave a Comment


This Blog


Favorite Non-technical Sites or Blogs

Privacy Statement