Non-Clustered Indexes – Usage and Benefits

clustered-indexindex

I know the differences between clustered and non-clustered indexes. Can someone tell me the various scenarios where we actually prefer non clustered index over a clustered index ?

Best Answer

The following is written for SQL Server, but should be quite the same with other RDBMS...

The clustered index is physically sorted on the storage media and will cover all columns of your table - as if they were include columns.

A good clustered index is bound to a column with an implicit sort quality, such as insertDateTime or a running number (e.g. with an IDENTITY column). Any insertion is put at the end and is placed correctly at once. The worst clustered index is bound to a column with no sort order such as UNIQUEIDENIFIER. The effect will be a fragementation of 99.9%. (But a look on NEWSEQUENTIALID might be interesting...)

It is important to keep in mind, that other indexes use an existing clustered index as lookup-key. If this lookup is slow due to fragementation, other indexes will be slow too.

Imagine a UNIQUEIDENTIFIER column which you want to use as FK-column somewhere else. This was a case, where a non-clustered key would provide a much smaller index, better to maintain and better to rebuild. In case this was a clustered key the performance would most probably be very bad...