Indexes increase data access performance. I tried creating indexes but there was no difference in the time cosumption. Am i missing something here?
My schema looks like this. (49 Columns). Id – PrimaryKey (Clustered Index)
Id | Name | Age | CountryId | CourseId | ....... | EnrolledOn
There are around 425,000 records in the table. Considering country and course are the columns used to filter the records, I created a composite index comprising these two columns (These two columns are foreign keys).
I tried the following query.
Select * From Students Where CountryId = 1 And CourseId = 1
Without indexes and with indexes the query took 11 seconds.
Note : Around 415,000 records match the above condition. Will this be a reason for no difference in the time consumed.
Can anyone help me on this.
CREATE NONCLUSTERED INDEX IX_Country_Course ON Students(CountryId,CourseId)
An index will do little if you request almost every row from a table. In that case it will only speedup if you only select fields that are in the index so the original table is not needed to get all requested data.
So select only countryid and you might see some benefit in the above problemcase