Index in Database
An index is best described as a pointer to data within a table in a database.
is analogous to an index found at the back of a book or within a telephone directory.
An index is created either on a table or within a view.
Purpose of Index in database
the primary purpose of an index is to retrieve the large amount of data from a table efficiently and fast,
Heap
Any table or view that does not have any form of indexes is termed a heap, Heap is basically a database or a table that is not sorted in a particular way.
Lets create Table as a head (Without any Indexes)
We can see our records in PhoneBook Table without any sorting order. Now if we insert any record it added at a last row in table
Clustered Index in Sql Server
Clustered indexes organize the data rows in a table or view according to their key values, allowing for only one clustered index per table. When you create a clustered index, it does not require additional space.
Check data in Table ‘Phonebook’ , we can see all records are sorted by column lname. now with the clustered index in place, if we insert a record, it will automatically be sorted by column lname.
- Can cross check this index in left panel
- Just double click this index to open index properties in design mode
- Advantage of a Clustered Index
- It primarily sorts the data based on the column you index to, and it does not take up space. All it does is rearrange it.
Can create a clustered index on multiple columns