Microsoft SQL Server Database Systems

09 Feb 2016, 10:54

SQL Server Code to Generate Status Report Of DB Health

Untitled

If you are suspecting your SQL Server Database is acting strange and you fear it is moving into corruption, try running the below script to Generate Detailed report of all User Tables Integrity and data correctness..

 

In order for this Script to run, the Database has to be in Single user Mode, so the below script makes you Change it to Single mode, run the scan then Change it Back to multi User.

 

Just Replace YourDBName_Here with the name of the database you want to check.

 

Cheers.


--Changing it to Single Mode

ALTER DATABASE YourDBName_Here SET SINGLE_USER

GO

 

--Performing the Full Scan Report

DBCC CHECKDB('YourDBName_Here', REPAIR_REBUILD)

GO

 

--Changing it Back to Multi users Mode

ALTER database YourDBName_Here SET MULTI_USER

 

GO