Categories
Sql Server

What are Indexes and it’s types

Index:-An index is a collection of pages associated with a table used to improve the performance.Indexes are used to point to the location of a row on data page instead of  look through all data pages in a table. Planning useful indexes is one of the most important factor of improving query performance. It requires an understanding of both index structure and how data is used.

Three fundamental indexing options offered by SQL Server:-

  1. Heaps:-A heap is a table without clustered index. The data rows were not stored in any particular order, and there are no particular order to the sequence of data pages. The data pages are not linked in a linked list. SQL Server always maintains data pages in a heap unless a clustered index is defined on the table.
  2. Clustered indexes:-A clustered index sorts and  also stores the data rows of the table in order of the clustered index key. The clustered index is treated as a B-tree (balanced tree). Each page in a B-tree is called an index node. The top node of the B-tree is called the root node. The bottom level node in the index is called the leaf level.
  3. Non-clustered indexes:-In Non-clustered indexes have also the same B-tree structure as in clustered indexes except that the data rows of table are not sorted and stored in order based on their non-clustered keys.
Types Of Indexes:- 
Clustered A clustered index sorts and stores the data rows of the table or view in order based on the clustered index key. The clustered index is implemented as a B-tree index structure that supports fast retrieval of the rows, based on their clustered index key values.
Non-clustered A nonclustered index can be defined on a table or view with a clustered index or on a heap. Each index row in the nonclustered index contains the nonclustered key value and a row locator. This locator points to the data row in the clustered index or heap having the key value. The rows in the index are stored in the order of the index key values, but the data rows are not guaranteed to be in any particular order unless a clustered index is created on the table.
Unique A unique index ensures that the index key contains no duplicate values and therefore every row in the table or view is in some way unique.Both clustered and nonclustered indexes can be unique.
Index with included columns A non-clustered index that is extended to include nonkey columns in addition to the key columns.