• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

SQL Server - Clustered vs Non-clustered

Contributor ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

Hi,

When should I use clustered index versus non-clustered index?

Thanks in advance!
TOPICS
Getting started

Views

741

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Sep 09, 2008 Sep 09, 2008
AppDeveloper,

You should use a clustered index when the index will be used in the majority of the SELECT statements run to query the table. Use non-clustered for less frequently used indexes.

Disclaimer: Your mileage may vary and this is just my rule of thumb.

Question: What version of SQL server are you using?

Votes

Translate

Translate
LEGEND ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

AppDeveloper wrote:
> Hi,
>
> When should I use clustered index versus non-clustered index?
>
> Thanks in advance!

IIRC Non-Cluster Indexes are used when the values in the index field(s)
are unique across all records.

Clustered Indexes are when the values are *not* unique and thus come in
'clusters' of values.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

Hi lan,

Then how come some of the foreign key columns in my company's existing database are storing non-unique values (duplicate values exist) and they (these foreign key columns) are non-cluster indexed?

Based on SQL Server Books Online, their definition is as follows, but I'm just not exactly sure when (in what situation(s)) to use non-cluster and when to use cluster.

Clustered: Creates an object where the physical order of rows is the same as the indexed order of the rows...

Non-clustered: Creates an object that specifies the logical ordering of a table. With a nonclustered index, the physical order of the rows is independent of their indexed order.

Thanks in advance again.




Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

AppDeveloper wrote:
> Based on SQL Server Books Online, their definition is as follows, but I'm just
> not exactly sure when (in what situation(s)) to use non-cluster and when to use
> cluster.

O.K. Obviously I did not Recall Correctly!

>
> Clustered: Creates an object where the physical order of rows is the same as
> the indexed order of the rows...
>
> Non-clustered: Creates an object that specifies the logical ordering of a
> table. With a nonclustered index, the physical order of the rows is independent
> of their indexed order.

Using that definition it is a case of how is the data in the tables. If
the data is stored on the disk drive in the order of the index, then you
can use a clustered index.

Otherwise use a non-clustered.

This is something I have never had a large enough database to worry
about using anything other then the non-clustered.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

AppDeveloper,

You should use a clustered index when the index will be used in the majority of the SELECT statements run to query the table. Use non-clustered for less frequently used indexes.

Disclaimer: Your mileage may vary and this is just my rule of thumb.

Question: What version of SQL server are you using?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

You might try using the Database Engine Tuning Advisor tool included with SQL 2005, this can help you identify what indexes might be needed in your database.
http://msdn.microsoft.com/en-us/library/ms188639(SQL.90).aspx

Designing Indexes
http://msdn.microsoft.com/en-us/library/ms190804(SQL.90).aspx

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 09, 2008 Sep 09, 2008

Copy link to clipboard

Copied

LATEST
Many thanks to both of you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation