|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 10:01 PM
Points: 3,
Visits: 34
|
|
Hi,
I just shrunk the database using DBCC SHRINK statement. what would be the best approach to fix the fragmentation after shrinking the database?
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 9:51 AM
Points: 37,648,
Visits: 29,899
|
|
Rebuild all indexes.
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, July 19, 2012 8:47 AM
Points: 260,
Visits: 366
|
|
Rebuild all indexes via alter <<index name>> on <<table name>> rebuild
then run exec sp_updatestats
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: 2 days ago @ 8:30 AM
Points: 153,
Visits: 1,278
|
|
My understanding is that rebuilding all indexes will also update their statistics with full scan - so sp_updatestats will just replace the statistics with sampled ones.
Cheers,
JohnA
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:21 AM
Points: 964,
Visits: 632
|
|
John__A is correct. Don't run the update stats sp after rebuilding all the indexes because you will be replacing stats that are based on a full scan with ones that are based on a sampled scan, possibly resulting in less accurate statistics.
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Wednesday, May 01, 2013 10:01 PM
Points: 3,
Visits: 34
|
|
| do i need to rebuild all indexes one by one for each tables? as there might be a hundreds of indexes all up
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Thursday, July 19, 2012 8:47 AM
Points: 260,
Visits: 366
|
|
I recommend to use MS script using sys.dm_db_index_physical_stats at http://msdn.microsoft.com/en-us/library/ms188917.aspx
Version 2008 R2, but versions up to 2005 are available.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:21 AM
Points: 964,
Visits: 632
|
|
| Or just make a maintenance plan that rebuilds them all in all databases. Schedule it for off hours though.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, August 29, 2011 8:12 PM
Points: 20,
Visits: 27
|
|
Will "Rebuild all indexes" will also work with Indexes on composite primary keys?
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 9:21 AM
Points: 964,
Visits: 632
|
|
|
|
|