Today we will see quick script which will check integrity of all the database of SQL Server.
EXEC sp_msforeachdb 'DBCC CHECKDB(''?'')'
Above script will return you lots of messages in resultset. If there are any errors in resultset they will be displayed in red text. If everything is black text there is no error. Typical output of above script will be like image included in the article.

Image displayed above is only partial image.
Reference : Pinal Dave (http://www.SQLAuthority.com)
Yes this is a neat trick, however, sp_msforeachdb is going to be deprecated in a future release of SQL and Microsoft doesn’t recommend using it in scripts.
Hi Pinal,
Its really a nice script & I am using this in our enviornment. But I need you to kindly explain the results of DBCC CHECKDB.How to read the results of this query.
Thanks in advance.
Regards,
Sanjeev Kumar
Pls help me……….
i have design the website in asp.net……..
but have some problem…..
I set the question and answers randomly from the sql database….. and also check the result of the question in the database. checking is the problem……….
When page load occurs every questions are checked before answered…….. i have confused with this……
thanks in advance
how to find sql server database is in use yes/no
EXEC sp_who
If any entry with status runnable for that database, it is in use
i want to know which other pc is connecting my database.
how can i check this sate.
You can use a profiler or sp_who
EXEC sp_who
Pingback: SQL SERVER – Beginning New Weekly Series – Memory Lane – #002 « SQL Server Journey with SQL Authority