Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
When do we use indexes in sql queries....?
Posted

Indexes are used by sql queries and not used in sql queries.

You create indexes when your queries are not performing well.
 
Share this answer
 
Comments
sravani.v 22-May-12 7:53am    
My 5!
Mehdi Gholam 22-May-12 8:01am    
Thanks
Member 8660975 22-May-12 7:54am    
can we use it where in a query 'IN' keyword is used..?
Mehdi Gholam 22-May-12 8:00am    
The IN keyword is for specifying values for columns, not indexes.
 
Share this answer
 
Comments
Mehdi Gholam 22-May-12 8:01am    
5'ed
sravani.v 22-May-12 23:58pm    
Thank you Mehdi
In short:
When there are thousands of records in a table, retrieving information will take a long time.
Therefore indexes are created on columns which are accessed frequently, so that the information can be retrieved quickly.

Indexes can be created on a single column or a group of columns.
When a index is created, it first sorts the data and then it assigns a ROWID for each row.

Effective indexes are one of the best ways to improve performance in a database application.
 
Share this answer
 
Comments
Member 8660975 22-May-12 8:04am    
Thanks for the reply..
which is prefered for fast fecthing of records 'IN' or 'Indexes' ..?
Prasad_Kulkarni 22-May-12 8:07am    
You're welcome!
As I answered when you want to access huge data, Indexes are better.
Member 8660975 22-May-12 8:26am    
ok thanks again...
Member 8660975 22-May-12 8:30am    
actually i need to fetch records of students using their roll no which is primary key. so i need to fetch top 5 records. so now using indexes is better or v can mention the 5 roll numbers in 'IN' clause and fetch records.
Sorry for more questions.
I suggest also reading Clustered and Nonclustered Indexes Described[^]. It's a short description, but gives quite nicely the big picture.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900