info@techdevops.com | 437-991-3573 | Data Engineering Services
TechDevOps.com
Resources Tools
Experts in Microsoft SQL Server on Windows, Linux, Containers | Clusters, Always On, FCI | Migrations, Cloud, Performance



Automate DBCC UpdateUsage per select list of databases
by BF (Principal Consultant; Architecture; Engineering)
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 + '] DBCC UPDATEUSAGE (' + @db_name + ');' + '' + Char(10) + 'GO')
Fetch c_db_processing Into @db_name
End

Close c_db_processing
Deallocate c_db_processing