Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
Can anyone please help me to get understanding about index, Clustered and Non Clustered Index clearly. I have read many articles about this but not able to understand.

Thanks.
Posted

I think this should be clear enough : Indexes in MS SQL Server[^]

Important points:

- Table can have only one clustered index
- Clustered index will be created on a table by default the moment a primary key is created on the table
- Non-clustered index uses a clustered index (if defined) or the heap to build itself.
 
Share this answer
 
Comments
Member 10431234 28-Nov-13 9:00am    
Thanks for reply it was really helpful nd easy to understand. Thanks :)
Clustered indexes are also known as Index Organized Tables (IOT). Which is a more descriptive name.
The primary key index IS the table. So to get a record you only need to search the index. The DB doesn't need to get a reference to the RowID to fetch the data.
So it's very fast when using the primary key index.

But as the nature of a BTree index is that it's self balancing you don't have a RowID on the record. This means that secondary indexes needs to reference the primary index to get a record. So using secondary indexes is slower than on a normal table.

Another drawback is that ALL fields will be in the index, so it's unfit for using whenever you have more than one field that's not actually used in the index.
It also means that IOTs are unfit for using when you have fields with (largely) varying sizes, such as large varchar fields or binary data fields.

So usage is quite limited, I'm more or less only using them in junction tables that's used for one direction joins only.

Some well written info here[^].
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900