DEV Community

loading...
Cover image for Maintenance: Update Statistics

Maintenance: Update Statistics

Antoine
mainly .Net but looking for great stuff about anything
・1 min read

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 !

Discussion (0)