Executing CHECKDB on all user databases via TSQL

Run below Query. And once the query executes completely, go through the SQL Server Error log to see the results.

declare databases cursor for
select name from sys.databases
    where name <> 'master' and name <> 'tempdb'
    and name <> 'model' and name <> 'msdb'
declare @dbname varchar(100)

open databases
fetch next from databases into @dbname

while @@fetch_status=0
begin
print @dbname + ' - ';
DBCC CHECKDB (@dbname) with no_infomsgs;
fetch next from databases into @dbname
end

close databases
deallocate databases

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.