Database Marked as Corrupt in Microsoft SQL Server: How Can It Be Repaired?

Ralf Sagmeister | July 7, 2026

MSQL

Causes of the problem and steps for a proper recovery procedure.

Causes and Procedure

Anyone who works with databases in Microsoft SQL Server is surely familiar with this problem. After an unexpected event, a database may become inaccessible and be flagged as potentially corrupted. There can be many reasons for this:
 

  • The database is damaged (marked as “corrupt”).
  • There is not enough disk space available for SQL Server to restore the database at startup.
  • The database cannot be opened due to defective files, insufficient RAM, or insufficient disk space.
  • The database files are locked by the operating system, third-party backup software, etc.
  • An unplanned termination of the SQL Server service, a power outage, or a hardware failure.

To be able to work with the database again, you must perform the following steps:
 

  • Open Microsoft SQL Server Management Studio.
  • Connect to the affected SQL Server instance
  • Open a new query
  • Copy the following script into the query and replace
    “[corrupted database]” with the name of your
    database marked as corrupted.

USE master;


GO/***********************************************************************************************************

Find the correct database name that

is marked as faulty***********************************************************************************************************/

SELECT DBName=NAME, [Status]=state_desc
FROM master.sys.databases
WHERE

state_desc='SUSPECT'/***********************************************************************************************************

Now replace [DATABASENAME] with the name from the results and repair the database

—
set the database to emergency mode—
set the database to single-user mode—run the database repair. WARNING: May

result in data loss***********************************************************************************************************/

ALTER DATABASE [DATABASENAME] SET EMERGENCY
GO

ALTER DATABASE [DATABASENAME] SET SINGLE_USER
GO

DBCC CHECKDB ([DATABASE_NAME], REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS;


GO/***********************************************************************************************************

Next, run another check on the database:-As

above,

replace [DATABASENAME]***********************************************************************************************************/

USE [DATABASENAME]
GO

DBCC CHECKDB WITH NO_INFOMSGS;


GO/***********************************************************************************************************

If the check shows that the database is error-free, switch from single-user to multi-user mode—

as above,

replace [DATABASENAME]***********************************************************************************************************/

USE master;
GO

ALTER DATABASE [DATABASENAME] SET MULTI_USER


GO/***********************************************************************************************************

You should then immediately back up the repaired database.

***********************************************************************************************************/

 

  • Execute the query [vc_single_image image="10521" img_size="full"]

Afterward, the database can be used to its full extent again. Please note that inconsistencies may occur due to data loss. However, the following principle applies here: An existing backup has never hurt anyone.