We have a table form which we would like to select data in both accending and decending order.
Do we need to create 2 indices?
How would SQL Server process a request for all rows in decending order if there was only an accending clustered index?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Short-Answer : No. If this is only for one column, then the same index should be usable in both cases. As for traversing, since indexes are doubly-linked lists, they can be traversed in either order.
http://msdn.microsoft.com/en-us/library/aa933132%28SQL.80%29.aspx
Other Details…
If you have a (say..ascending) index on emp_name, then both the queries below should be able to make use of it without aditional sorting.
The problem is when the query references more than one column and the order by for these two is in different order.
In this case, if you use the desc clause when creating the index, an additional sort can be avoided.
Check this link. It is spcific to Oracle, but I believe SQL Server works pretty much the same way.
http://forums.oracle.com/forums/thread.jspa?messageID=4061884
Another useful link :
http://www.mssqltips.com/tip.asp?tip=1337