Click here to Skip to main content
16,017,235 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hello guys,


I want to what will happen if i create 2 non-cluster index on same column?
because in my windows application there was 1 non-cluster index on particular table
at that time it was slower and i create another non-cluster for same column and i didn't notice but it's giving me faster result than earlier.i don't know what exactly happened that earlier index was created long time ago may be that was corrupted .
i just want to know is it best practice to keep 2 index on same column?
Posted
Updated 8-Sep-11 2:26am
v2

If the index is the same then just use the newer one, SQL query optimizer will determine which index to use based on a best fit approach. Indexes don't get currupted they might get out dated, meaning they were filled and updated and fragmented based on old data patterns which might have changed.

It is good practise to cleanup and re do the indexes once in a while.
 
Share this answer
 
Comments
vipul ghadge 8-Sep-11 9:45am    
Okzz Thank You :)
Even though you can create 2 indexes on the same column, there's no point of doing that. Normally the only thing that happens is that you use extra space.

There are few special situations when having more than one index would be beneficial, but these are rare cases.

As Mehdi already pointed out you should rebuild the indexes regularly. It could be once a month or once a year depending how often you have changes in your data.

Another thing is your statistics. The problem that queries become slower could be caused by the fact that the statistics are out-of-date. Updating statistics is something you should do for example every week, meaning a lot more often than rebuilding indexes.

To ensure that you have good statistics:

  • check from your database options that Auto Create Statistics and Auto Update Statistics are both true
  • update your statistics on every table using UPDATE STATISTICS[^]
  • OR create for example a maintenance plan where you update the statistics on regular intervals
 
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