info@techdevops.com
TechDevOps.com
Explore Tools
Experts in Microsoft SQL Server Operations, Performance, Replication, Cloud & Migrations



Automate DBCC UpdateStats per select list of databases
by BF (Senior MSSQL Operations - Enterprise, Cloud, Strategy)
2018-05-18









T-SQL:


Declare @db_name varchar(250)

Declare c_db_processing Cursor For

Select [name] from master.sys.databases order by name asc

Open c_db_processing

Fetch c_db_processing INTO @db_name

While @@Fetch_Status = 0
Begin
Print('USE ['+ @db_name + '] Exec sp_updatestats' + '' + Char(10) + 'GO')
Fetch c_db_processing Into @db_name
End

Close c_db_processing
Deallocate c_db_processing