Wednesday, December 14, 2011

Difference between Clustered and Non-Clustered Index in SQL-SERVER

Posted by Rahul Kharde at 12:26 AM

There are clustered and non-clustered indexes. A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.

A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Using DML (Data Manipulation Language) statement on cluster index column have performance issues since it has to update the index each and every time a DML gets executed.

Clustered Index
Non-Clustered Index
Only one per table
Can be used many times per table
There can be only 1 Clustered index in a table. This is usually made on the primary key. Whereas non-clustered index can be up to 249
Clustered is physical sorted index
A non clustered index is a special type of index in which the logical order of the index
Data retrieval faster
Insert and update statements faster
Leaf nodes in B-Tree structure contains actual rows.
Leaf pages in B-Tree structure contains pointers to actual rows.

Example

CREATE TABLE Student
(
StudID INT PRIMARY KEY CLUSTERED,
FirstName VARCHAR(100),
LastName VARCHAR(100),
Address VARCHAR(100) UNIQUE NONCLUSTERED
)
GO
CREATE NONCLUSTERED INDEX Student_nonclust ON Student(FirstName)
GO
After creating the CLUSTERED and NONCLUSTERED index it will show like



If you enjoyed this post and wish to be informed whenever a new post is published, then make sure you subscribe to my regular Email Updates. Subscribe Now!


Kindly Bookmark and Share it:

YOUR ADSENSE CODE GOES HERE

0 comments:

Have any question? Feel Free To Post Below:

 

Popular Posts

Recent Comments

© 2011. All Rights Reserved | Help to understand .Net | Template by Blogger Widgets

Home | About | Top