Ad Code

Queries, Indexes, Unique Index, Data


When we have quries to get required data then why we need to creat indexes ? I can retreive any required data by using quries then why we create uniqe index..........


Kindly explain this whole concept in detail and mentioned some examples where it will show the actual work of index ( where we cannot get our required data from quries)



A table definition is not a great deal of use in getting to the data quickly. For this, some sort of cross-reference facility is required, where for certain columns of information within a table it should be possible to get to the whole record of information quickly. 
Example:
   If you think of any book, for example, as a table, the cross-reference you would use to find information quickly is the index at the back of the book. You look in the book index for a priece of information. When you find the listing for that information in the index, you will find that it is associated with a page number, or a pointer, which directs you to where you can find the data you are looking for.
   Very much like this, you define an index in SQL Server so that it can locate the rows it requires to satisfy database queries faster. If an index does not exist to help find the necessary rows, SQL Server has no other option but to look at every row in a table to see if it contains the information data required by the query. This is called a table scan, which takes a lot of time to find the desired information.

   When searching a table using index, SQL Server does not go through all the data stored in the table; rather, it focuses on a much smaller subset of that data, as it will be looking at the columns defined within the index, which is faster. Once the record is found in the index, a pointer states where the data for that row can be found in the relevant table.
Hopefully, it will clear the concept.
Reactions

Post a Comment

0 Comments