-4

The below was the Database(SQL Server/Oracle) question asked by Interviewer to me.

How do i call a specific index In case if i have multiple indexes?

I have no idea on it. I searched in google but failed.

Billa
  • 5,226
  • 23
  • 61
  • 105

1 Answers1

2

You can provide hints to the optimiser.

Index hints look like this:

SELECT /*+ INDEX(<table name> <index name> <optional free text comment> */ field1, field2...

Example:

SELECT /*+ INDEX(patients sex_index) use sex_index because there are few
   male patients  */ name, height, weight
FROM patients
WHERE sex = 'm';
Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • Can you give some scenario and elaborate it. showing me like a commented code. :( i am confusing – Billa Feb 06 '13 at 13:34
  • I have given an example telling you the syntax. If you add a specific SQL query and the name and table for the index you wish to use I can show you how to add the hint. – Klas Lindbäck Feb 06 '13 at 13:49