How to Repair MDF Files in SQL Server Database?

Important Note :  Before proceed to following steps, we strongly advise taking your database backup without fail. You need to proceed it at your own risk.

We will use the DBCC (database console commands) commands in the SQL server management studio to repair the corrupt MDF files of the SQL database.

There are many DBCC commands to check and repair the SQL database like DBCC CHECKDB, DBCC DBREPAIR.

To fix the corrupt MDF files in the database follow the below steps.

  1. Open the SQL server management studio.

  2. Now click on New query.

  3. Write the below script in query and execute it.

    EXEC sp_resetstatus [YourDatabase];
    ALTER DATABASE [YourDatabase] SET EMERGENCY
    DBCC CHECKDB ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)
    ALTER DATABASE [YourDatabase] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    DBCC DATABASE ([YourDatabase], REPAIR_ALLOW_DATA_LOSS)
    ALTER DATABASE [YourDatabase] SET MULTI_USER
    

Replace the YourDatabase with your actual database name. Once you execute it there should be no more corrupt MDF files in your database.

 

Related Articles

How to change MySQL root password from WHM?

In this article, we will describe steps to change the root password of MySQL server from WHM....

How to Repair a MySQL Database Through Linux and Windows Command Line?

This article describes how to repair MySQL database tables through Linux and Windows command...

Fix - PHPMyAdmin Error You should upgrade to MySQL 5.5.0 or later

Problem statement Recently we upgraded phpMyAdmin version from 4.0.10.12 to 4.5.3.1 in our...

How to set ut8mb4 for mysql via phpMyAdmin?

Please refer to the following steps to change MySQL server collation via phpMyAdmin Login to...

How to edit the my.cnf file of MySQL in Linux VPS?

Linux VPS and Dedicated server customers can edit MySQL configuration settings by modifying...

  • 0 Users Found This Useful

Was this answer helpful?