Query for Rebuild all Indexes with update statistics of Database at Single Click?

TS R 0 Reputation points
2023-03-08T10:31:23.75+00:00

Hi All,

Can you please help me to add update statistics to below script . need deploy on Azure Pass environment

DECLARE @TableName VARCHAR(255)

DECLARE @sql NVARCHAR(500)

DECLARE @fillfactor INT

SET @fillfactor = 80

DECLARE TableCursor CURSOR FOR

SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName

FROM sys.tables

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName

WHILE @@FETCH_STATUS = 0

BEGIN

SET @sql = 'ALTER INDEX ALL ON ' + @TableName + ' REBUILD WITH (FILLFACTOR = ' + CONVERT(VARCHAR(3),@fillfactor) + ')'

PRINT (@sql)

EXEC (@sql)

 

FETCH NEXT FROM TableCursor INTO @TableName

END

CLOSE TableCursor

DEALLOCATE TableCursor

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Zahid Butt 961 Reputation points
    2023-03-08T18:53:14.91+00:00
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.