An Overview of Cluster and Noncluster Index In SQL Server

Andrew Jackson ~ Modified: September 24th, 2015 ~ SQL Master Database ~ 4 Minutes Reading

Overview of SQL Server index

In my previous article I have discussed about SQL Error 4014 and know its causes and solutions. Now, in this article I am going to discuss about SQL Server index. At first I will give you a book example, we all are reading books. So, the index page of a book, which contains all the information about book’s chapters and their page numbers are enough information to find out a page or a chapter in a book. Similarly, In SQL Server indexes are the set of pages that arranged in a tree structure (B-Tree), which is hierarchical in nature. Basically two types of indexes are available in SQL Server.

  • Clustered index
  • Non-clustered index

These two cluster and noncluster indexes and their working procedure I will discuss after describing the basic structure of index in SQL Server.

Basic Structure of Index in SQL Server

The SQL Server creates indexes on columns in a table or views and provides a rapid way to access the data according to the values. Indexes are helpful in enhancing the overall performance of SQL Server.

There are three filtering levels, which helps in faster access of the data.

  • Root Level
  • Intermediate Level
  • Leaf Level

Root Level: This is the highest level of the index. If the table is large and the search is performed against an indexed column, the query engine starts finding from the root node and the root node navigates down to the intermediate nodes and intermediate node navigates down through leaf node the search query is not found. There is only a single root page in an index.

Intermediate Level: This is the middle level of the index. The intermediate level comes in between Root Level and Leaf Level. If the table is too small then there is no intermediate level.

Leaf level: This is the last level of the index. If the search not found between Root Level and Intermediate Level, then the query engine navigates down to Leaf Level.

So, these three indexing level sort the data pages and then helps the query engine to find the searched result quickly and enhance the performance of SQL Server.

Now the question is that, how these indexing levels work on cluster and noncluster index?

What is Cluster and Noncluster Index?

Clustered Index

In a clustered index the data rows are stored at leaf leaf level of the index and the indexed values of a clustered index are sorted in either ascending or descending order. It is possible that, there can be one clustered index available on a view or table. The data is sorted in a table if there is clustered index defined on that table and that table is known as clustered table. A table that doesn’t have any clustered index, is called as heap.

Non-Clustered Index?

The B-tree works same in nonclustered indexes as it works in clustered indexes, but the differences are that the data pages are same, but the leaf pages are different and each row in a table has a one key-pointer that is stored by leaf level. The page pointers and index keys are stored by the leaf-level pages, And also a pointer of the row offset table on the data pages. By merging page pointer and row offset number is also called the row ID. The index keys and page pointers of other index pages are stored by root and intermediate levels. With the same size of keys, The nonclustered indexes need more space than clustered indexes.

Conclusion

This article gives an overview of cluster and noncluster index. In which we know, what is indexing in SQL Server and how the data pages are managed in indexing, Also we know about cluster and noncluster index and how they are different from each other. Without Indexing, It is very difficult to search a query within the SQL Server database and also it degrades the performance of SQL Server.