Useful script to rebuild table indexes and update stats You can update the queries based on your requirement. To update the table stats --Query to update the table stats SELECT N'UPDATE STATISTICS ' + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + ' ;' FROM INFORMATION_SCHEMA.tables AS t WHERE t.TABLE_TYPE = N'BASE table'; GO To re-build table indexes: --To rebuild table index DECLARE @myDatabaseName NVARCHAR(255) = N'your-database-name'; DECLARE @runningTableName NVARCHAR(255); DECLARE @cmd NVARCHAR(1000); DECLARE @name NVARCHAR(100)= 'your-database-name'; -- Populate the database cursor. DECLARE myDatabaseLevelCursor CURSOR READ_ONLY FOR SELECT @name; OPEN myDatabaseLevelCursor; FETCH NEXT FROM myDatabaseLevelCursor INTO @myDatabaseName; WHILE @@FETCH_STATUS = 0 BEGIN -- In this command we're declaring table level cursor SET @cmd = 'DECLARE myTableCursor CURSOR READ_ONLY FOR SELECT '...