[Database] - UPDATE STATISTICS for all SQL Server Databases
Saturday, July 14, 2018
Run update statistics for SQL Server database.
Step 1: Run following the SQL script below:
DECLARE @SQL VARCHAR(1000) DECLARE @DB sysname
DECLARE curDB CURSOR FORWARD_ONLY STATIC FOR
SELECT [name]
FROM master..sysdatabases
WHERE [name] NOT IN ('model', 'tempdb')
ORDER BY [name]
OPEN curDB FETCH NEXT FROM curDB INTO @DB WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @SQL = 'USE [' + @DB +']' + CHAR(13) + 'EXEC sp_updatestats' + CHAR(13)
PRINT @SQL
FETCH NEXT FROM curDB INTO @DB
END
CLOSE curDB DEALLOCATE curDB
Results:
USE [Dummy] EXEC sp_UpdateStats
USE [master] EXEC sp_UpdateStats
USE [msdb] EXEC sp_UpdateStats
USE [MSSQLTips] EXEC sp_UpdateStats
USE [MSSQLTips_DUPE] EXEC sp_UpdateStats
USE [Northwind] EXEC sp_UpdateStats
USE [Sitka] EXEC sp_UpdateStats
USE [Utility] EXEC sp_UpdateStats
Step 2: Copy and run database which you want to update statistics.
If you want to know how to use run update statistic alse problem and solution, please access to link below:
The article use source from: https://www.mssqltips.com/sqlservertip/1606/execute-update-statistics-for-all-sql-server-databases/
Bài liên quan
Comments[ 0 ]
Post a Comment