Which should be used after messing up clustered index? Update statistics, Reindex or Reorganize
-
If I have a clustered single column index, e.g FooId in SQL Server 2008, 2012 and I know I have messed up the order of the rows to not have sequential order of the FooId column anymore, which command/s should be used: Update statistics Rebuild Reorganize EDIT Scenario FooId is a clustered pk of type sequential uniqueidentifier, but for keeping it simple it this post we use #1 as id values. #1 inserted #2 inserted #3 inserted #1 selected #1 deleted #2 selected #2 deleted #2 inserted (that is reusing the clustered PK of #1) #1 inserted (that is reusing the clustered PK of #1) Isn't this going to break the sequential order? Will it not be stored like this now: #3 #2 #1 //Daniel
-
Answer:
You may have misunderstood the way a clustered index works - http://msdn.microsoft.com/en-us/library/ms177443%28v=sql.105%29.aspx the data is logically ordered in the sequence of the clustering key, although it's possible for the clustered index to become physically fragmented as page-splits occur when new data is inserted. If you want to reduce fragmentation either REBUILD or REORGANIZE can be appropriate. The rule of thumb is to do nothing when fragmentation is below 5%, REORGANIZE when fragmentation is between 5% and 30%, and REBUILD when fragmentation is above 30%. Index fragmentation is recorded in the DMV http://technet.microsoft.com/en-us/library/ms188917%28v=sql.105%29.aspx. See also http://technet.microsoft.com/en-us/library/ms189858%28v=sql.105%29.aspx It's worth noting that unless you are running SQL Server Enterprise edition, REBUILD cannot be performed on-line - meaning that your table will be inaccessible for the duration of the command. REORGANIZE is always carried out on-line.
Daniel at Database Administrators Visit the source
Related Q & A:
- How can PCR or mass spectrometer be used to detect an unknown new bacteria to which no human has exposed?Best solution by Yahoo! Answers
- What is the name of the large board, reflecting and diffusing light, which is used in a photography studio?Best solution by Yahoo! Answers
- Which products, used by few today, will be essential in five years?Best solution by Yahoo! Answers
- In which country are mostly solar panels used?Best solution by pureenergies.com
- Which of the following is characteristics of an index fossil?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.