SQL Server cannot attach a BAK file because attach works for MDF files only. Restore is the command that opens a BAK file. Choose between the Restore dialog in SSMS, T-SQL and recovery software. Methods one and two need a healthy backup whose version does not exceed the server. Recovery software exports a damaged or unreadable BAK file into a new database. Work on a copy of the file first.
Many searchers treat a BAK file like an MDF file. Attach points to the wrong command.
This guide explains the right term for a BAK file and every route that works. Methods go from least to most effort, followed by the errors that stop most restores.
Microsoft rules out a restore on a Database Engine release that predates the backup source. Check the versions before you try any method.
Does SQL Server Attach BAK Files?
No. Attach adds database files that already exist and a BAK file stores a backup of a database. SQL Server builds the database again from the backup with RESTORE DATABASE.
| Item | MDF File | BAK File |
|---|---|---|
| What it is | Live primary data file of a database | Backup of a database |
| SQL Server action | Attach | Restore |
| T-SQL statement | CREATE DATABASE with FOR ATTACH | RESTORE DATABASE |
| Guide | attach steps for an MDF file | Methods #1 to #3 below |
What to Check Before the Restore?
Check six items before you start:
- Version. Microsoft requires the server to match or exceed the version of the server that made the backup.
- Upgrade. An older database upgrades during the restore and Microsoft states that compatibility level 90 becomes level 100.
- Backup Source. A backup from another server needs the Device option in SSMS.
- Network Path. The Locate Backup File window accepts a remote file by its fully qualified UNC name according to Microsoft.
- Encryption. Encrypted databases need access to the certificate or asymmetric key according to Microsoft.
- Trust. Check files from unknown sources on a test server with DBCC CHECKDB.
Per Microsoft the Database list in SSMS shows only databases from the msdb backup history. Choose Device for a backup from another server.
Which Backup Types Come in a BAK File?
Backup type decides the restore order. Microsoft describes the restore order as a full backup first and an optional differential backup next followed by all log backups in sequence in its restore and recovery overview.
| Backup Type | Restore Order | Recovery Option |
|---|---|---|
| Full | First | NORECOVERY when more backups follow |
| Differential | After the full backup | NORECOVERY when logs follow |
| Transaction log | In sequence after the others | RECOVERY on the last log |
Microsoft states that databases in the SIMPLE recovery model restore from a full backup alone or from a full and a differential backup. Log backups do not apply to them.
3 Methods to Attach a BAK File in SQL Server
Methods #1 and #2 cost nothing and need a healthy backup. Method #3 brings in recovery software for damaged files.
| Feature | Restore Dialog | Script | Recovery Software |
|---|---|---|---|
| Cost | SSMS feature | SSMS feature | Free preview and licensed export |
| Best for | One time restores | Scripts and backup chains | Damaged or unreadable backups |
| Needs | Healthy backup | Healthy backup | Windows computer and file copy |
| Main limit | Version match | Path typos | Demo export limit |
Method #1: Restore the BAK File Through SSMS (Free)
Choose the dialog for a healthy backup from this server or a different one. Microsoft lists every dialog page in restore a database backup using SSMS.
- Start at Databases in Object Explorer with a right click and choose Restore Database.
- Choose Device as the Source and click the ... button.
- Choose File as the Backup media type and click Add.
- Select the backup file in the Locate Backup File window and click OK.
- Select the database name in the list under the device box.
- Enter a different name in the Database field of Destination for a copy.
- Accept To the last backup taken or use Timeline for a point in time.
- Tick the backups in the Backup sets to restore grid.
- Open the Options page and accept RESTORE WITH RECOVERY.
- Tick Close existing connections when users are active and click OK.
Note. Microsoft names two common messages. SQL Server reports a backup of another database when the name already exists and reports a missing exclusive access when users remain connected. Fixes sit in the error table below.
Method #2: Use T-SQL to Restore the Backup (Free, Best for Backup Chains)
Scripts handle a single full backup and a chain of backups alike. Microsoft states that RESTORE HEADERONLY finds the position of a backup set inside a file.
RESTORE HEADERONLY
FROM DISK = N'D:\Backups\LoanDB.bak';
One statement restores a single full backup.
RESTORE DATABASE LoanDB
FROM DISK = N'D:\Backups\LoanDB_full.bak'
WITH RECOVERY;
Chains of full, differential and log backups follow another pattern. Microsoft recommends NORECOVERY on all statements until the recovery point and a separate RESTORE WITH RECOVERY at the end.
RESTORE DATABASE LoanDB
FROM DISK = N'D:\Backups\LoanDB_full.bak'
WITH NORECOVERY;
RESTORE DATABASE LoanDB
FROM DISK = N'D:\Backups\LoanDB_diff.bak'
WITH NORECOVERY;
RESTORE LOG LoanDB
FROM DISK = N'D:\Backups\LoanDB_log.trn'
WITH NORECOVERY;
RESTORE DATABASE LoanDB
WITH RECOVERY;
Microsoft states that RECOVERY rolls back uncommitted transactions and makes the database ready. NORECOVERY makes the database unusable until the last step. List the databases that still wait for the final statement with the query below.
SELECT name, state
FROM sys.databases
WHERE state = 1;
WITH REPLACE removes the existing database according to Microsoft. Use a new name for a safe copy.
Method #3: Recover and Restore a Damaged BAK File With EmailDoctor (Scan Free, Export Licensed)
Backups that SQL Server cannot open need another route. EmailDoctor SQL Backup Recovery previews the tables of the backup before any export. Vendor notes say scanning works without a SQL Server installation but an export requires admin rights on a SQL Server.
Test with a copy of the backup. Vendor notes list 25 records per table as the demo cap.
Add the Backup and Recover It
- Open the recovery software on your Windows PC.
- Click Browse, select your LoanDB.bak copy and click Open.
- Accept Auto detect or set the SQL Server release yourself.
- Press Recover and wait until the progress bar ends.
- Select a table in the left pane and check its rows.
Export the Data to a New Database
- Press Export and select the SQL Server database option.
- Enter the server name and choose the login mode.
- Choose Create New Database and type LoanDB_Restored as the name.
- Choose the With Schema & Data export type.
- Click Export and refresh SSMS to see the restored tables.
How to Test the BAK File Before the Restore?
Test the backup first. RESTORE VERIFYONLY checks the backup set and restores nothing.
RESTORE VERIFYONLY
FROM DISK = N'D:\Backups\LoanDB_full.bak';
Microsoft details the options in its RESTORE VERIFYONLY reference. Errors 3241 and 3013 during the check point to a damaged or mismatched file as the RESTORE HEADERONLY error guide explains.
Which Errors Stop a BAK Restore?
Five problems cause most failed restores:
| Message | Reason | Fix |
|---|---|---|
| Backup belongs to another database | A database with that name exists | Choose Overwrite the existing database (WITH REPLACE) or restore under a new name |
| Exclusive access could not be obtained | Users are connected to the database | Tick Close existing connections |
| Backup fails on an older server | The backup source has a newer version | Restore on a server whose version is at least that of the source |
| Encrypted database fails | The certificate or key is missing | Restore the certificate or key before the database |
| Media family error | The file is damaged or incomplete | Follow the RESTORE HEADERONLY error guide |
Use Method #3 with a copy of the file when every fix fails. Steps for a lone MDF file sit in the primary data file guide.
Frequently Asked Questions
Is Attach Possible for a BAK File?
No. Attach works for MDF files. SQL Server restores a BAK file with RESTORE DATABASE.
Does SSMS Open a BAK File Without a Restore?
No. SSMS shows backup details through RESTORE HEADERONLY but tables appear only after a restore. Recovery software previews the tables without a restore.
Does a Backup Restore on an Older SQL Server?
No. Older servers reject a backup from a newer release. Restore the file on a server whose version is at least that of the backup source.
Can I Restore a BAK File From Another Server?
Yes. Select Device under Source in SSMS and add the file. Microsoft states that the Database list shows only the local msdb history.
Can I Restore a Backup From a Network Path?
Yes. Microsoft states that the Locate Backup File window accepts a remote file by its fully qualified UNC name.
Does a Restore Upgrade the Database?
Yes. Older databases upgrade to the version of the new server. Microsoft states that compatibility level 90 becomes level 100.
Can I Restore Under a Different Database Name?
Yes. Enter the new name in Destination under the Database field. Add MOVE clauses when the file paths already exist.
Does NORECOVERY Make the Database Usable?
No. Microsoft states that NORECOVERY does not roll back uncommitted transactions. Finish with RESTORE WITH RECOVERY.
Do I Need the Certificate for an Encrypted Backup?
Yes. Encrypted backups restore only with access to the original certificate or asymmetric key.
Can Recovery Software Restore a Corrupt Backup?
Yes. Recovery software recovers the objects of the file and exports them to a new database. Check the preview before you export.
Does the Demo Cap the Rows?
Yes. Vendor notes list 25 records per table as the demo cap. Licensing removes the cap.
Author’s Verdict
BAK files never attach. SQL Server restores them through the Restore dialog or through T-SQL.
Check the version before you start because an older server cannot accept a newer backup. Use NORECOVERY for backup chains and finish with RECOVERY.
Recovery software saves the data of an unreadable backup. Work on copies.
- Attach works for MDF files and restore works for BAK files.
- Restore in SSMS and T-SQL restore need a healthy backup that matches the server version or predates it.
- NORECOVERY suits backup chains and RECOVERY ends them.
- WITH REPLACE removes the existing database.
- Recovery software exports the data of a damaged backup to a new database.
- Work on copies.
Next Read: Restore a SQL Database From a BAK File
Also Read: Fix the RESTORE HEADERONLY Error | Restore the Primary Data File