Click here to Skip to main content
16,019,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when to use cluster index and non- cluster index.which index would be more preffered in terms of performance.Can you please help me with an example?
Posted

A clustered index is SUPER fast. This is because, instead of an index of JUST the index column, it's an index of ALL your columns, row by row. That means that SQL Server looks up the index and finds the whole row. This is why you can only have one clustered index. This is incredibly fast. It also means that inserts and especially deletes, are REALLY slow. Use a clustered index for data you read to a lot, and rarely write to. Otherwise, use a normal index. If you add to a list but never delete from it, it's also a candidate for a clustered index. The issue is, if you delete, all the rows below need to be copied up, remember that a clustered index has ALL The data at the index level, so the hole left by a delete needs to be filled.

If you need the speed of a clustered index on data you want to also delete, consider using a deleted flag to filter out deleted rows ( this would need an index too, but not the clustered one ).
 
Share this answer
 
There can only be one clustered index on a table because it defines how the data is actually stored on the disk.

See http://technet.microsoft.com/en-us/library/ms190457.aspx[^] for more info.
 
Share this answer
 
v2

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