I have a very large SQL Server 2008 R2 database (1.5TB) and will be copying some data from column to column within the same table. I've been told that the schema has a large number of indexes and was wondering if there is a default query or script that will rebuild all the indexes. Have also been advised to update the statistics at the same time?
Each of the 30 tables has one clustered index and 13x non-clustered indexes
Thanks.
Daniel's script appears to be a good all encompassing solution, but even he admitted that his laptop ran out of memory. Here is an option I came up with. I based my procedure off of Mohammad Nizamuddin's post on TechNet. I added an initial cursor loop that pulls all the database names into a temporary table and then uses that to pull all the base table names from each of those databases.
You can optionally pass the fill factor you would prefer and specify a target database if you do not want to re-index all databases.
Try the following script:
Also
I prefer(After a long search) to use the following script, it contains
@fillfactor
determines how much percentage of the space on each leaf-level page is filled with data.for more info, check the following link:
https://blog.sqlauthority.com/2009/01/30/sql-server-2008-2005-rebuild-every-index-of-all-tables-of-database-rebuild-index-with-fillfactor/
and if you want to Check Index Fragmentation on Indexes in a Database, try the following script:
For more information, Check the following link:
http://www.schneider-electric.com/en/faqs/FA234246/
Also a good script, although my laptop ran out of memory, but this was on a very large table
https://basitaalishan.com/2014/02/23/rebuild-all-indexes-on-all-tables-in-the-sql-server-database/
Replace the "YOUR DATABASE NAME" in the query below.