Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Clustered Index and the table on which it is created both contain the actual data?

Clustered indexes sort and store the data rows in the table or view based on their key values.

https://msdn.microsoft.com/en-IN/library/ms190457.aspx

It means if a table has a clustered index, then the rows of that table will be stored on disk in the same exact order as the clustered index.

Secondly, the leaf nodes of a Clustered Index contains data pages of the table on which it is created.

https://technet.microsoft.com/en-us/library/ms177443%28v=sql.105%29.aspx

So, my question is that same data is stored in the Clustered Index and table on which it is created?

If Yes, then what is the need to sort the table in the same order as clustered index? Because clustered index itself stores the row-level data in it’s leaf nodes.

And if NO, then what is the actual theory behind the creation of Clustered Index?

like image 501
user1780538 Avatar asked Feb 13 '15 12:02

user1780538


People also ask

Is clustered index separate from the table?

A clustered index is not a separate index from table, it is the table. The clustered index is not a separate entity like it is with other index types, but rather a mechanism for sorting the table and facilitating quick data access. So, we can either say data is stored in clustered index or data is stored in table.

How is data stored if there is no clustered index What about when you create a clustered index?

If a table has no clustered index, its data rows are stored in an unordered structure called a heap.

How is data stored if there is clustered index?

In a clustered index, when rows are inserted, updated, or deleted, the underlying order of data is retained. The rows of data are only stored in the leaf nodes at the lowest level of the index. These are the data pages that contain all the columns in the table, ordered by the clustered index columns.

Can we have both clustered and nonclustered index on table?

There can be only one clustered index per table. However, you can create multiple non-clustered indexes on a single table.


1 Answers

The data is stored in the leaf level of the clustered index - that IS the table data!

It's not stored in the table and in the clustered index - the clustered index's leaf level IS the table data.

like image 119
marc_s Avatar answered Nov 15 '22 09:11

marc_s