Tuesday, February 1, 2011

What to do with a "Suspect" Content Database in SharePoint

Our team leverages a robust Hyper-V environment supporting many virtual machines to support our various development projects. Collectively, they all share a physical SQL Server 2008 machine to store the SharePoint Configuration and Content databases. While installing FAST seach, we encountered an issue where one of our SQL databases was marked suspect. 


After some consideration, we suspected an unexpect shutdown was likely the cause. While we had backups, we decided to look for a programmatic solution to save time. The following script was the fruit of our efforts:

EXEC sp_resetstatus ‘YourSuspectDatabase’;

ALTER DATABASE YourSuspectDatabase SET EMERGENCY

DBCC checkdb(’YourSuspectDatabase’)

ALTER DATABASE YourSuspectDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CheckDB (’YourSuspectDatabase’, REPAIR_ALLOW_DATA_LOSS)

ALTER DATABASE YourSuspectDatabase SET MULTI_USER

Simply copy and paste this query in query analyzer and replace YourSuspectDatabase with the name of your database. Enjoy!