SQL Server with Mr. Denny

Mar 26 2009   3:00AM GMT

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

Denny Cherry Denny Cherry Profile: Denny Cherry

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.

Denny

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: