How to Repair and Rebuild SQL Database Manually

March 6, 2019 | Views: 407

Begin Learning Cyber Security for FREE Now!

FREE REGISTRATIONAlready a Member Login Here

Applications working on SQL database platform are easy to use but they have risk of data loss because of SQL MDF File. Despite Database Administrator maintains the SQL database it is prone to corruption as it is highly affected by external factors. Operating system errors, abrupt system shutdown and changes made by user affect the SQL database, so one should be ready to deal with such errors and to repair the SQL database.

Here are two free methods to repair corrupt SQL and rebuild damaged database without any error. Follow, the below methods to retrieve the data and fix SQL Errors

Fix SQL Errors with DBCC CHECKDB 

  • Open the SQL Database and then go to console
  • Type the command DBCC CHECKDB ‘Database Name’, to check database status
  • Check the database index, if the index ID is greater than 1 than recreate it
  • If the Index ID is displayed with values O or 1 then type the following commands for recovery
    • DBCC CHECKDB (Name of Database repair_fast)
    • DBCC CHECKDB (Name of Database repair_rebuild)
    • DBCC CHECKDB (Name of Database repair_allow_data_loss)
  • Replace Name of Database with your database name. In this way, you can repair and rebuild the SQL database without any errors.

Repair SQL Database with Server Management Studio

  • Check the version of SQL you are using and then download the SQL Server Management Studio, you are using
  • Install and start the SQL Studio to run query
  • Now Run the commands in order as given
    • EXEC sp_resetstatus [Database Name]
    • ALTER DATABASE [Database Name] SET EMERGENCY
    • DBCC checkdb ([Database Name]), here enclosed the database name with brackets.
    • 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
  • Execute the command and check database status. The file will open without any errors and SQL database will get repair.

These methods enable Database Administrators to fix the SQL issues and repair corrupt MDF files instantly. DBA should act immediately to prevent the database from further loss and these methods will help out.

Share with Friends
FacebookTwitterLinkedInEmail
Use Cybytes and
Tip the Author!
Join
Share with Friends
FacebookTwitterLinkedInEmail
Ready to share your knowledge and expertise?
Comment on This

You must be logged in to post a comment.

Our Revolution

We believe Cyber Security training should be free, for everyone, FOREVER. Everyone, everywhere, deserves the OPPORTUNITY to learn, begin and grow a career in this fascinating field. Therefore, Cybrary is a free community where people, companies and training come together to give everyone the ability to collaborate in an open source way that is revolutionizing the cyber security educational experience.

Cybrary On The Go

Get the Cybrary app for Android for online and offline viewing of our lessons.

Get it on Google Play
 

Support Cybrary

Donate Here to Get This Month's Donor Badge

 
Skip to toolbar

We recommend always using caution when following any link

Are you sure you want to continue?

Continue
Cancel