If your company operates constantly (24/7) your servers are always on. Sometimes you may face power failure due to the maintenance of some power stations. In order to avoid electric power failure, my initial suggestion is you can setup backup power generators, battery backups also called UPS (Uninterruptible Power Source). Let me explore my experience with you. I’ve had a power failure. Suddenly, the power went out. A few seconds later when the power came on, I turned on, the server then I saw that my main database files were corrupted. Sometimes due to power failure, the hardware is expired or the database files will be removed automatically.
These database records are very important for us and we need to recover these records as soon as possible. If we don’t know the exact solution then what we will do? We will restart the server multiple time and it will take too much time. At some point, our database files are recovered but mostly the database files are not recovered with this method. When we try to open the database, we continuously receive a message from the system with corruption.
We don’t need to worry about it. In this article, I will show you multiple solutions that how we can handle all of these situations.
In this solution, if we have the recent backup file of our database then we don’t need to worry. we can solve this problem using installed MS SQL Management Studio on the computer or server.
Follow the below steps to repair your corrupt SQL database:
Step 1: We need to run the MS SQL Management Studio and select the corrupted database.
Step 2: Do the right click on the selected database and you will see multiple options.
Step 3: We see that there are many options but I choose the options that are needed for the solution. We see that there are many options but I choose the options that are needed for the solution. After the right selection, we will see multiple options. Here we need to select the device because we have the backup file in our system (Computer).
Step 4: Here we can see that the right backup file is selected successfully.
Step 5: In step five or in the last step we just need to press the OK button then we will see that our database is restored successfully.
In some cases, a CHECKDB T-SQL Command can be enough to repair the damaged database:
Use your_database GO
–You need to set the database to single-user mode first
ALTER DATABASE your_database SET SINGLE_USER GO
–Then repair your database
DBCC CHECKDB(your_database, REPAIR_REBUILD) GO
–Once repaired, run this to return to multi-user mode:
ALTER <database-name> SET MULTI_USER
In this solution, we will use a software called Stellar Repair for MS SQL. Using this software, we can solve multiple problems in MS SQL Server. First, we need to download and install the SQL Database Repair Software. You need to follow few simple steps to repair the corrupt SQL database.
Step 1: This is the main interface of the software
Step 2: Select the corrupt MDF file
Step 3: Check the preview of all repairable database objects
Step 4: Stellar Repair for MS SQL allows the user to save the repaired file in the desired form. Here I’m storing my database file as an MDF file. For storing the database as an MDF file we need to select these options in the last small window. Then press the Save button. Our database file is stored successfully now we can open this database file in MS SQL Management Studio without any error message. You can also save your output file in more formats here you can see CSV, HTML, and XLS by selecting the option new database. If you find any error on this page during the selection you can refresh the window by pressing the refresh button.
In this article, we discussed how we can handle corruption in our database. There are multiple reasons but power failure is most of the common reason for database corruption. If we use the above solutions, I’m sure that we can solve these types of corruption in some minutes. If the problem is not solved with solution one, we need to try with the second solution.