SQL SERVER – ReIndexing Database Tables and Update Statistics on Tables


When any data modification operations (INSERT, UPDATE, or DELETE statements) table fragmentation can occur.
DBCC DBREINDEX statement can be used to rebuild all the indexes on all the tables in database.
DBCC DBREINDEX is efficient over dropping and recreating indexes.
DBCC DBREINDEX --This feature will be removed in a future version of Microsoft SQL Server

Execution of Stored Procedure sp_updatestats at the end of the Indexes process ensures updating stats of the database.


USE DATABASENAME
GO
EXEC sp_MSforeachtable @command1="print '?' DBCC DBREINDEX ('?', ' ', 80)"
GO
EXEC sp_updatestats
GO

Alternate :

USE DATABASENAME
GO
EXEC sp_MSforeachtable @command1="print '?' ALTER INDEX ALL ON ? REBUILD WITH (ONLINE = ON, FILLFACTOR = 90)"
GO
EXEC sp_updatestats
GO

0 comments:

Post a Comment

Your Location