DEV Community

Cover image for Maintenance: Update Statistics
Antoine
Antoine

Posted on

Maintenance: Update Statistics

Photo by Ben Hershey on Unsplash

SQL Azure let you define maintenance windows.

But you can use a script to perform maintenance tasks such as updating index. This script has a lot of option.

DECLARE @dbname nvarchar(200) 
SELECT @dbname = DB_NAME()

EXECUTE dbo.IndexOptimize
@Databases = @dbname,
@FragmentationLow = NULL,
@FragmentationMedium = 'INDEX_REORGANIZE,INDEX_REBUILD_ONLINE',
@FragmentationHigh = 'INDEX_REBUILD_ONLINE',
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@UpdateStatistics = 'ALL',
@OnlyModifiedStatistics = Y,
@Indexes = 'ALL_INDEXES',
@MinNumberOfPages = 1,
@LogToTable = 'Y'
Enter fullscreen mode Exit fullscreen mode

This blog explains how using it with Azure Automation, to perform it recurrently.

Hope this helps !

Top comments (0)