So really, how many clustered indexes can I create on a table?

This used to be a very easy question to answer as the answer was 1. However these days, with some creativity you can get some extra ones.

The basic definition of a clustered index is that it has one or more indexed columns, and all other columns are added to the index as non-indexed columns.

Until SQL Server 2005 we didn’t have the ability to add additional columns to the index without sorting them. SQL Server 2005 introduced us to the concept of included columns.

So technically you can still only have 1 clustered index per table (an index created with the keyword CLUSTERED in the CREATE INDEX statement). But you can create as many nonclustered indexes as you need (up to the 999 nonclustered indexes per table that you are allowed) and as long as you include every other column in the database the index will effectively function like a clustered index.

Thanks to Erland and Hugo for the interesting discussion at PASS last November which prompted this post, not to mention letting me hang out with them for a few hours and pick their brains.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?