Improve the performance by using Indexing in SQL

Index in SQL

have you ever faced slowness while fetching the records in the SQL. If yes, then you are at the right place 😉. First let’s understand the reason behind it.

So at the beginning of any project each table has small amounts of data and when we retrieve the data we don’t feel slowness. But when the project is very big and most of the tables store thousands of records then query execution will be slow if the table is not indexed. Because of indexing is not used in the table SQL will visit all the rows and and will retrieve the matching records.

Index:-

Types Of Index :-

1) Clustered Index:-

Example:-

CREATE CLUSTERED INDEX studentIDX ON STUDENTS(StudentID DESC);

2) Non-Clustered Index:-

Now let’s check how performance is getting improved by using Indexing on table.

Without Indexing:-

If we don’t use any index in the table then SQL will visit all the records row by row hence execution time will get increased if records are in the thousands or more than that.

As in given Screenshot it is visible that in “Number of Rows Read” parameter value is same as the number of records present in the table.

With Clustered Index:-

If we use clustered index then execution time will get decreased.

As in the given Screenshot it is visible that in “Number of Rows Read” parameter value is 1 and execution time has also decrease.

Bhagavad Gita Verse:-

I am a Software Developer in MNC company and I do Freelancing and blogging as well.