C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Interview   Jobs   Projects   Offshore Development    
Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing | Talk to Us |



My Profile

Gifts

Active Members
TodayLast 7 Days more...









Clustered Index in SQL Server


Posted Date: 23 Jul 2008    Resource Type: Articles    Category: Databases

Posted By: Vijaya       Member Level: Diamond
Rating:     Points: 25



Overview:

In this article I would like to give you an over view on what is Clustered Index and what are key points that you have to consider in designing the clustered index on a table.

Introduction:

Primarily in SQL server there are two types of indexes, clustered index and Non-Clustered index. Let me give you very basic difference between these types of indexes. These two indexes are different in terms how the data is stored. In Clustered index the leaf-nodes contains the data where as in Non-clustered index leaf-nodes contains the bookmarks to the actual data. In other words data is sorted and stored based on the Clustered Index. So that’s the reason you can have only one Clustered index per table.

Index Creation:

Now let’s get into action on how to create Clustered index.
The syntax to create index is:


CREATE [UNIQUE] [CLUSTERED|NONCLUSTERED]
INDEX index_name
ON table (column [ASC|DESC] [ ,...n ] )
[WITH {IGNORE_DUP_KEY|DROP_EXISTING|SORT_IN_TEMPDB}]
[ON filegroup ]


CLUSTERED or NONCLUSTERED: Optional clause. If it is not explicitly listed, then NONCLUSTERED index is created. So to create Clustered Index you need to specify “CLUSTERED” Clause.

Scenarios to have Clustered indexes:

1) If the query has a WHERE clause with operators like BETWEEN, >, >=, <, and <=.
2) If the query is returns large result sets.
3) If the query uses JOIN clauses.
4) The query accesses values in a column sequentially. For example, a query on EmployeeIDs between 10000 and 900000
5) If the query uses an ORDER BY clause or a GROUP BY clause. The index might remove the need to sort the data because the data is already ordered.

Criteria to create Clustered index:

1) Contains unique values or, failing that, contain mostly distinct values.
2) Are defined as IDENTITY. Each value in the column is known to be unique.
3) Are often used to sort data returned by a query. Having data in a clustered index that is already sorted in a desired order can save the cost of sorts during the query.

Criteria to not create Clustered index:

1) There is a wide key for each data row.
2) Values in the key columns undergo frequent changes. Because data in a clustered index is sorted on key column values, a change in those values means that data rows have to be moved into their correctly sorted positions after any changes.







Responses

Author: Nirupa Rani Acharya    27 Jul 2008Member Level: Bronze   Points : 0
thanks 4 d this...


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Vijaya Kadiyala  .  Clustered Index  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Database Constraints Part 2
Previous Resource: How to delete the Duplicate records in sql
Return to Discussion Resource Index
Post New Resource
Category: Databases


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use