A simple question on how database Indexes work.
Suppose i have a table ‘Student’ with columns id(primary_key), name and GPA. Assume that i have an index on id and on no other columns
Now if i query for a record using name and GPA(not with id), it has to search all records for a match. what is the advantage of index here ?
Are the indexes effective only when the query contains the indexed columns ?
You are correct. There is no advantage, except that unique indexes may also enforce uniqueness
Basically yes for finding matching rows, although indexes can also be used to help sorting if the
order bycontains an indexed column