40 pts.
 Clustered and Non-clustered Index
Hi, I have one table having more than 3 millions rows with following columns: [SITE_ID] [USER_NAME] (http://xs434.xs.to/xs434/08513/queries-columns997.jpg or http://xs.to/xs.php?h=xs434&d=08513&f=queries-columns997.jpg) Please help.. Thanks Sharma

Software/Hardware used:
ASKED: December 17, 2008  1:51 PM
UPDATED: December 17, 2008  8:47 PM

Answer Wiki:
You need to create a single index which contains all the columns which you are in your WHERE clause as well as your ORDER BY clause. The columns in your SELECT statement should be put into the index as included columns (if using SQL 2005 or higher). You will probably end up with a few different indexes to handle all your queries. Each query with a different ORDER BY Clause will need it's own index, with the Order by columns included in the index in the order you are sorting by them. The queries which don't have ORDER BY statements can all be handled by one index just make sure that you have all the columns that all the queries return listed in the INCLUDE section. Look at the execution plan to see what index is currently being used.
Last Wiki Answer Submitted:  December 17, 2008  8:47 pm  by  Denny Cherry   64,520 pts.
All Answer Wiki Contributors:  Denny Cherry   64,520 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _