question

OracleApprender avatar image
OracleApprender asked

What is the basic difference between clustered and a non-clustered index?

Could anyone explain the differences between clustered and a non-clustered indexes to me?. Please let me know if there are any specific requirements to be used in special cases. Thank you.

sql-serverindexes
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

OracleApprender avatar image
OracleApprender answered

The difference is that, Clustered index is unique for any given table and we can have only one clustered index on a table. The leaf level of a clustered index is the actual data and the data is resorted in case of clustered index.

Whereas in case of non-clustered index the leaf level is actually a pointer to the data in rows so we can have as many non-clustered indexes as we can on the db.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeff Moden avatar image Jeff Moden commented ·
Actually, the leaf level contains data that is the same as it is in the table and the pointer. If all of the data requested by the query is located in the leaf level of the NCI, then the query uses the data directly from the index instead of from the table.
0 Likes 0 ·
KillerDBA avatar image
KillerDBA answered

Here's a little intro...

Clustered and Non-Clustered Indexes

It's SQL Server-specific.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sakshi Maurya avatar image
Sakshi Maurya answered

Cluster index sorts the data with respect to the column on which it is applied, where as non-clustered index do not, it is just a logical sorting. Thus we can have only single clustered index and multiple non-clustered index on a table. Primary index on a table is clustered index. By default CREATE INDEX statement creates a non-clustered index

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swati_kadam avatar image
swati_kadam answered
When we create primary key on table,oracle automatically creates Clustered index on that column.As we can create only one primary key on table,like we can create one and only one clustered index on table. When we create any normal index on column it is by default Non clustered index. As we can create many unique indexes on table,like we can create many non clustered indexes on table.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

swati_kadam avatar image
swati_kadam answered
As we can create only one primary key on table same way we can create only one clustered index on table. That means Oracle automatically creates clustered index on primary key column. As we can create many unique indexes on table same way we can create many non-clustered indexes on table. Primary key -- Clustered Index Unique Index -- Non clustered Index
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nadir.Ramani avatar image
Nadir.Ramani answered
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeff Moden avatar image
Jeff Moden answered
Gosh, there's a lot of bad info on this on this thread. First, a Clustered Index does not have to be unique and it does not have to be the Primary Key although it usually helps to be both. There is no such thing as a "Primary Index" in SQL Server although the Primary Key will create an index as does any UNIQUE constraint. It IS true that there can only be one Clustered Index on a table and that's because the leaf level of the Clustered Index is actually the table data itself. All other indexes are, by definition, Non-Clustered Indexes and they contain copies of the key columns and any INLUDE columns in the leaf level of the Non-Clustered Index. One of the most important parts about Clustered Indexes is that each and every Non-Clustered Index contains the key columns from the Clustered Index. This is not a trivial question and I've only scratched the surface here. My very strong recommendation is to open up Books Online and do a deep study of Heaps, Clustered Indexes, and NonClustered Indexes before you look at anything else on the Internet on this subject.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ghanesh avatar image
Ghanesh answered
I FOUND THIS BLOG WHICH EXPLAINS ABOUT INDEXES IN SQL SERVER, I HOPE THIS CAN HELP http://teachmesqlserver.blogspot.in/2014/08/indexes-in-sql-server_27.html
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Karthikaqpt avatar image
Karthikaqpt answered
A table can have only one clustered index on it. Clustered indexes don’t need to store a pointer to the actual row. A table can have more than one Non-Clustered index. Non clustered indexes store both a value and a pointer to the actual row that holds that value. Both are the main terms in [sql][1] [1]: https://www.youtube.com/watch?v=7Vtl2WggqOg
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jason_clark03 avatar image
jason_clark03 answered
Please have a look on this article and understand what is the main difference between clustered and non-clustered index [ http://www.sqlserverlogexplorer.com/overview-of-cluster-and-noncluster-index/][1] [1]: http://www.sqlserverlogexplorer.com/overview-of-cluster-and-noncluster-index/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.