How to repair a damaged or inoperative Microsoft SQL Server database
Step-by-step description of repairing Microsoft SQL Server database items of any version from a damaged *.mdf file:
- Download, install and open SQL Server Repair Toolbox from the site: https://www.repairtoolbox.com/download/SQLServerRepairToolboxInstall.exe.
- Select the damaged *.mdf file on the first page of the program.
- Select an export method:
- Save as SQL scripts to disk
- Execute SQL script directly in the database
- Select the data to be restored and saved.
- Click Start recovery.
How to repair SQL Server database files
How to repair SQL database file? The MS SQL repair tool reads *.mdf and *.ndf files and saves data, structure, links, etc. as SQL scripts or exports directly to Microsoft SQL Server through direct connect. If database have a SUSPEND state in Management Console then our software can helps to recover data from it.
Main capabilities of the MSSQL database repair tool include:
- Repair data for MS SQL Server 7/2000/2005/2008/2008 R2/2012/2014/2016.
- Repair data type.
- Repair table data.
- Repair View.
- Repair Stored Procedures.
- Repair Functions.
- Repair Triggers.
- Repair Indexes.
- Repair Primary Keys.
- Repair Foreign Keys.
- Repair Constraints.
- Repair databases comprising multiple files.
- Work with Table Partitions.
- Export data to MS SQL Server.
- Saves restored data to disk as SQL scripts.
- Flexible and practical interface of Microsoft SQL Server repair database software.
- Ability to select data for exporting or saving.
- Works with Windows 98, NT 4.0, 2000, Me, XP, Vista and Windows 7/8/8.1/10/11.
Requirements
- Windows 98/Me/2000/XP/Vista/7/8/10/11 or
- Windows Server 2003/2008/2012/2016 and above
Read more...
Note:SQL Server Repair Toolbox is not freeware. Unlike open source programs, the users of SQL Server restoration application are provided with full support so they may consult its software team development and get all answers in time. SQL Server Repair Toolbox do not distributed under MPL or other GNU License.
FAQ
Answer:
There are two methods of saving recovered data generated by SQL Server Repair Toolbox:
- You can save data as SQL scripts on your hard drive and execute these scripts when needed. This will create tables and objects (indexes, procedures, functions and such), then import data to these tables.
- You can also run these SQL scripts using SQL Server Repair Toolbox by configuring a connection string to a particular data source (SQL Server or another database).
SQL scripts can differ regardless of the fact that they may be based on the same database files. This is related to certain syntax peculiarities in requests that are executed after establishing a server connection via ADO, as well as the execution of SQL queries in Query Analyzer shipped with Microsoft SQL Server (use of “:”, Go commands, etc.).
- Conversion of recovered data to SQL scripts and saving them on the hard drive
- Viewing of saved data
If you chose to save data to the hard drive, the program will automatically create a subfolder that will, in turn, be created in the folder specified by the user. All the scripts will be saved there. The names of the scripts being created comply with naming rules and consist of letters and digits, where words denote the script’s role, and digits refer to its number. There are numerous script types, for example:
- Types*.sql – user-defined data types.
- Tables*.sql – tables.
- Indexes*.sql – primary keys and indexes.
- ForeignKeys*.sql – foreign keys.
- Procedure*.sql – stored procedures.
- Function*.sql – user-defined functions.
- View*.sql – views.
- Triggers*.sql – triggers.
- Data*.sql – data tables.
The serial numbers of scripts are used for separating data and saving it to a multitude of small documents instead of one large file. It should be noted that each new file of the “Data” type can include data from one table only.
Attention: numbers may be missing in some files, which means that data is missing in some tables or it’s far from being complete.
- Script execution sequence
You can see the recommended execution sequence in the illustration below:
The sequence of script execution depends on existing restrictions for the current data and table structures. Please pay special attention to these factors:
- Specify a corresponding primary key if you want to create a foreign one. Thanks to this, these operations will be saved to various files that must be executed in this sequence.
- Prior to creating indexes and foreign keys, the program fills tables with data. This is required, as the referential integrity check is performed while populating the table where the foreign key is defined. When tables with foreign keys are populated to the tables with corresponding primary keys, an error occurs. Apart from this, this method has another characteristic. If the recovered data conflicts with the primary key, unique index and such, the table fill be populated anyway, but no restrictions will be created (index, primary key, ect.). If users need a different type of behavior, they can choose a specific script execution sequence.
- Creation of such objects as Procedures, Functions, Views, Triggers in the database has its peculiarities, since these objects may have very complex and intertwined dependencies. Procedure can refer to other Procedure objects, View can refer to Function, and Trigger can refer to all types of objects. Therefore, the program will not help untangle this knot of dependencies. Users need to manually identify all dependencies and launch SQL in the right sequence. Another possibility is to launch all the scripts of the group several times until there are no more error messages.
- The Install.bat file
The install.bat file is created to ensure automatic script execution. This file launches all the scripts that were previously saved by this program. The script execution sequence will be the same as when scripts are executed on a database. This batch file requires the isqlw tool to be installed, which is included in the client part of MS SQL Server. Please specify such parameters as Server name, Database name, User name, Password in the command line. For example: install.bat SQLServer SQLDatabase SQLUser SQLUserPassword.
Note:
- Parameters should be specified through spaces. If one of the parameters contains a space, you need to specify it in double quotes.
- Can’t swap parameters.
If the install.bat file is started without parameters, you will see a small instruction on launching this file.
- InstallTrusted.bat
If you authorize in Microsoft SQL Server via a Windows account, use the InstallTrusted.bat file. InstallTrusted.bat has 2 parameters: Server name, Database name.
Example: installtrusted.bat SQLServer SQLDatabase Detailed information about authorization via a Windows account can be found here: https://docs.microsoft.com/en-us/sql/relational-databases/security/authentication-access/principals-database-engine?redirectedfrom=MSDN&view=sql-server-ver15
- Viewing of saved data
Answer:
If your database consists of several files (a main MDF file and additional NDF files), you can restore it using SQL Server Repair Toolbox by selecting all MDF and NDF files in the source file selection dialog. To select all files, press and hold the CTRL key while selecting files with your mouse. You can also press and hold the Shift key and use arrow keys to modify the selection box and select the necessary files.
Note: files with the *.ldf extension contain logs of current operations and don’t need to be selected for database repair.
How it Works?
-
Download software from website.Download
-
Start Install software:
- Press on downloaded installation file in browser
- Select a downloaded installation file in Windows Explorer and press Enter or double click on it.
-
Run installation wizard.
-
Run program:
- Double click on icon on desktop
- or
- Select from main menu: Start | Programs | SQL Server Repair Toolbox | SQL Server Repair Toolbox.

-
Please confirm a start of recovery process.

Errors
Microsoft SQL Server database repair tool helps to fix many errors in SQL Server databases, for example:
- Corruption on data pages
- Metadata corruption Error
- SQL Server Page Level Corruption
- SQL Server Table Corruption Error
- Database consistency errors reported by DBCC CHECKB
- The header for file xxx.mdf is not a valid database file header.
- File Appears To Have Been Truncated By The Operating System.
- The FILE SIZE property is incorrect. (Micosoft SQL Server, Error:5172)
- The Index Allocation Map (IAM) Page is Pointed to by the Next Pointer of IAM Page.
- I/O error (bad page ID) detected during read at offset 0x###### in file FileName.mdf.
- During Redoing Of A Logged Operation In Database DatabaseName, An Error Occurred At Log Record Id.
- Sql Server Detected A Logical Consistency-Based I/O Error: Incorrect Checksum. (Microsoft SQL Server, Error:824)
Video Manual
I repaired 99.99% of MS SQL Server data from .MDF file.
VVEW virus coder encrypted my huge file.
Now I happy with my db.