Cluster index:
- By default, a column with a primary key already has a clustered index.
- Clustered indexes sort and store the data rows in the table or view based on their key values. These are the columns included in the index definition. There can be only one clustered index per table, because the data rows themselves can be sorted in only one order.
- The only time the data rows in a table are stored in sorted order is when the table contains a clustered index. When a table has a clustered index, the table is called a clustered table. If a table has no clustered index, its data rows are stored in an unordered structure called a heap.
Non-Cluster index:
- Nonclustered indexes have a structure separate from the data rows. A nonclustered index contains the nonclustered index key values and each key value entry has a pointer to the data row that contains the key value.
- The pointer from an index row in a nonclustered index to a data row is called a row locator. The structure of the row locator depends on whether the data pages are stored in a heap or a clustered table. For a heap, a row locator is a pointer to the row. For a clustered table, the row locator is the clustered index key.
- You can add nonkey columns to the leaf level of the nonclustered index to by-pass existing index key limits, 900 bytes and 16 key columns, and execute fully covered, indexed, queries.
Both of these indexes uses "B-tree" structure but in
Cluster index the "Leaf Node" actually points the physical data,
but in Non-Cluster index it point’s to the "Row ID" and then the
"Row ID" points to the "Leaf Node" of Cluster Index.
Difference:
Cluster
Index
|
Non-Cluster
Index
|
A table
can have only one Cluster Index as it point to the physical data.
|
A table
can have more than one Non-Cluster Index as it only points to the pointer of
Cluster Index.
|
Physical
data is stored as per Cluster Index.
|
There
is no relation of physical data.
|
The
leaf node of Cluster Index consist of data pages.
|
The
leaf node of Non-Clusted Index contain Index row.
|
Faster
to read than non-clustered as data is physically stored in index order
|
Quicker
for insert and update operations than a clustered index
|
Image:
No comments:
Post a Comment