May 29, 2014

Suspect Query for MS SQL 2005

How To Repair A Suspect Database In MSSQL 2005:

Issue
You have a database in MSSQL that is tagged as (suspect) and you are unable to connect to the database.

Possible Causes
The database could have become corrupted.
There is not enough space available for the SQL Server to recover the database during startup.
The database cannot be opened due to inaccessible files or insufficient memory or disk space.
The database files are being held by operating system, third party backup software etc.
There was an unexpected SQL Server Shutdown, power failure or a hardware failure.


Open Microsoft SQL Server Management Studio and connect to your database

  • Click the New Query button
  • Paste the following SQL script into your New Query page replacing [YourDatabase] with the name of your database.

EXEC sp_resetstatus DATABASE_NAME;

ALTER DATABASE DATABASE_NAME SET EMERGENCY

DBCC checkdb(DATABASE_NAME)

ALTER DATABASE DATABASE_NAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CheckDB (DATABASE_NAME, REPAIR_ALLOW_DATA_LOSS)

ALTER DATABASE DATABASE_NAME SET MULTI_USER

  • Click Execute
Your database should no longer be tagged as (suspect) and you should be able to access it.

No comments:

Post a Comment