Steps to repair .mdf files in SQL database.

kumkumsharma

Administrator
Staff member
If you want to repair corrupt MDF files then you have to use DBCC (Database console commands) in SQL server management studio. Many DBCC commands are available like DBCC CHECKDB, DBCC DBREPAIR.

To resolve this issue you can follow below steps:
  • Open SQL server management studio.
  • Here you will find option “New query”, you have to click on it.
  • You have to write below 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
  • You have to use yout database name in place of YourDatabase.
 
Top