Indexing

Indexing

by Austin Thomas -
Number of replies: 0

We use indexing to speed up the retrieval of our data. It does this by using a rapid path access method. One way to think about this is to compare it to an index in a book. Topics are grouped together alphabetically making them easier to search and find. This is a good thing when using select and where statements because it is better suited for how the data is organized. However, the negative is that it slows down the use of update and insert statements. 

Indexing is important because SQL first finds that value of the index you gave it and then uses the index to quickly locate the entire row of data. If we didn't use an index, SQL would have to scan the entire table instead of just going to the row of the index which as you can imagine would take more time. This is what we were talking about in class today, so it allows for exponentially less steps in looking through large data sets than it would to look through every entry until you find the desired result.

To create an index in SQL you use the CREATE INDEX function. Then, you give the index a name and tell it what tables/columns you want an index on. You then also either allow it to be in default which is ASC order or tell it to be in DESC order. It is important to remember that it is recommended to not use indexes on smaller data sets and tables with lots of NULL values. This makes sense because if there is not a lot of data, it would just be easier to look yourself and not use an index. I think for the NULL values as well that it would throw off the index because it would put all the NULL values sorted as if they were real values. 

A good website for learning how to make an index is https://www.tutorialspoint.com/sql/sql-indexes.htm

A website to learn about indexes and the different types  https://www.red-gate.com/simple-talk/sql/learn-sql-server/sql-server-index-basics/