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.
- Open the SQL server management studio.
- Now click on New query.
- 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.