Guide

How to restore a SQL Server database from a .bak file

To restore a SQL Server database from a .bak file, open SSMS, right-click Databases → Restore Database, choose the file as the device and confirm — or run RESTORE DATABASE ... FROM DISK in T-SQL. This guide covers both, plus how to restore under a new name, overwrite safely, fix orphaned users and solve the errors people hit most.

Before you start

  • Permissions: you need sysadmin or dbcreator to restore a new database, and to be the owner (or sysadmin) to overwrite an existing one.
  • Version: the target SQL Server must be the same version as the source or newer.
  • Disk space: the restored database needs as much space as the original data and log files, not just the size of the .bak.
  • File access: SQL Server reads the .bak using its service account, so put the file in a folder that account can read.
  • Compressed or encrypted copies: if the file is a .7z or encrypted archive, extract or decrypt it to a plain .bak first.

Step 1: inspect the backup file

Three read-only commands tell you what you're about to restore. FILELISTONLY is the one you'll use most: it lists the logical names (for example Sales and Sales_log) that the MOVE clause needs.

-- What's in the file? (database name, backup type, dates, SQL Server version)
RESTORE HEADERONLY FROM DISK = N'D:\Restore\Sales_FULL_2026-09-29_020000.bak';

-- Logical file names and original paths - you need these for MOVE
RESTORE FILELISTONLY FROM DISK = N'D:\Restore\Sales_FULL_2026-09-29_020000.bak';

-- Is the backup readable and complete? (doesn't restore anything)
RESTORE VERIFYONLY FROM DISK = N'D:\Restore\Sales_FULL_2026-09-29_020000.bak' WITH CHECKSUM;

VERIFYONLY checks that the backup set is complete and readable, and WITH CHECKSUM validates page checksums if the backup was taken with them. It's a good smoke test, but only a real test restore proves a backup works.

Step 2a: restore with SQL Server Management Studio

  1. In Object Explorer, connect to the instance, right-click Databases and choose Restore Database…
  2. Under Source, select Device, click …, then Add and pick your .bak file.
  3. Under Destination, type the database name. Use a new name (such as Sales_Copy) to restore alongside the original.
  4. On the Files page, tick Relocate all files to folder so the new database gets its own data and log file names.
  5. On the Options page, tick Overwrite the existing database (WITH REPLACE) only if you intend to replace it, and Close existing connections if users are connected. Leave recovery state as RESTORE WITH RECOVERY unless you still have differential or log backups to apply.
  6. If you're overwriting from a backup made on another server, untick Take tail-log backup before restore.
  7. Click OK and wait for “Database restored successfully”.

Step 2b: restore with T-SQL

Restore under a new name (WITH MOVE)

Use the logical names from FILELISTONLY. Every logical file needs its own MOVE to a new physical path, otherwise SQL Server tries to reuse the original database's files.

RESTORE DATABASE [Sales_Copy]
  FROM DISK = N'D:\Restore\Sales_FULL_2026-09-29_020000.bak'
  WITH MOVE N'Sales'     TO N'D:\SQLData\Sales_Copy.mdf',
       MOVE N'Sales_log' TO N'D:\SQLData\Sales_Copy_log.ldf',
       RECOVERY, STATS = 10;

Overwrite an existing database (WITH REPLACE)

REPLACE tells SQL Server you really mean to overwrite a database, even one with a different name inside the backup. Kick users off first:

USE master;
-- Disconnect everyone (rolls back their open transactions)
ALTER DATABASE [Sales] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

RESTORE DATABASE [Sales]
  FROM DISK = N'D:\Restore\Sales_FULL_2026-09-29_020000.bak'
  WITH REPLACE, RECOVERY, STATS = 10;

ALTER DATABASE [Sales] SET MULTI_USER;

Overwriting is irreversible

Before you replace a production database, take a fresh backup of it (or restore to a new name and compare first).

Apply differential and log backups (NORECOVERY)

Every step except the last uses NORECOVERY, which keeps the database in the restoring state so more backups can be applied. The final RECOVERY brings it online. Background on chains is in SQL Server backup types explained.

RESTORE DATABASE [Sales] FROM DISK = N'D:\Restore\Sales_FULL.bak' WITH NORECOVERY, REPLACE;
RESTORE DATABASE [Sales] FROM DISK = N'D:\Restore\Sales_DIFF.bak' WITH NORECOVERY;
RESTORE LOG      [Sales] FROM DISK = N'D:\Restore\Sales_LOG_1.trn' WITH NORECOVERY;
RESTORE LOG      [Sales] FROM DISK = N'D:\Restore\Sales_LOG_2.trn' WITH NORECOVERY;
RESTORE DATABASE [Sales] WITH RECOVERY;  -- bring it online

Step 3: fix orphaned users

Database users are linked to server logins by SID. When you restore to a different server, SQL-authenticated users whose logins were created separately end up with no matching login — they are “orphaned” and the application can't sign in. Find and fix them:

USE [Sales_Copy];
-- SQL-authenticated users with no matching login on this server
SELECT dp.name AS orphaned_user, dp.sid
FROM sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp ON dp.sid = sp.sid
WHERE dp.type = 'S'
  AND sp.sid IS NULL
  AND dp.name NOT IN ('dbo', 'guest', 'INFORMATION_SCHEMA', 'sys');

-- Create the login if it doesn't exist yet, then map the user to it
-- CREATE LOGIN [app_user] WITH PASSWORD = N'<strong password>';
ALTER USER [app_user] WITH LOGIN = [app_user];

ALTER USER ... WITH LOGIN replaces the older sp_change_users_login procedure, which is deprecated. Windows (domain) accounts normally don't become orphaned inside the same domain, because their SID is the same everywhere.

Common restore errors and fixes

Error 3154: the backup set holds a backup of a database other than the existing database

You're restoring over a database whose name differs from the one in the backup. Either restore to a new name with MOVE, or add WITH REPLACE if overwriting is really what you want.

Operating system error 5 (Access is denied)

Usually reported as Msg 3201 (“Cannot open backup device”) or as a directory lookup failure on a MOVE path. The SQL Server service account — not your Windows login — can't read the .bak or write to the target folder. Move the file into SQL Server's default Backup folder, or grant the service account access:

Command Prompt (as administrator) — default instance / Express instance
icacls "D:\Restore" /grant "NT Service\MSSQLSERVER":(OI)(CI)RX
icacls "D:\Restore" /grant "NT Service\MSSQL$SQLEXPRESS":(OI)(CI)RX

Mapped network drives aren't visible to the service either; use a UNC path such as \\nas\backups\file.bak.

Error 3169: backed up on a server running a newer version

The backup comes from a newer SQL Server than the one you're restoring on. There is no downgrade path. Upgrade the target instance, or move the data another way (script schema and data, or export/import). Check both sides with SELECT @@VERSION; and the SoftwareVersionMajor column of RESTORE HEADERONLY:

Major versionSQL Server
10.502008 R2
112012
122014
132016
142017
152019
162022

Error 3101: exclusive access could not be obtained

Someone (often your own SSMS query window) is connected to the database. Switch to master and use SET SINGLE_USER WITH ROLLBACK IMMEDIATE as shown above.

After the restore

  • Run DBCC CHECKDB on the restored database to confirm it's consistent.
  • A database restored on a newer version keeps its old compatibility level; raise it with ALTER DATABASE ... SET COMPATIBILITY_LEVEL once you've tested the application.
  • Test the application login, then schedule backups for the restored database if it's going into service.

Restore testing belongs in your routine, not just your emergencies — see the 3-2-1 backup rule for SQL Server.

Restore — FAQ

Can I restore a .bak file to an older version of SQL Server?

No. SQL Server can restore a backup only on the same or a newer version. To move data to an older version, script the schema and data, or export and import it, from the newer server.

How do I restore a .bak file under a different database name?

Use RESTORE DATABASE with the new name and a MOVE clause for every logical file, pointing to new physical file names, so the restore doesn't try to overwrite the original database's files.

Why is my database stuck in 'Restoring...'?

The last restore step used WITH NORECOVERY, which leaves the database waiting for more backups. If you have nothing else to apply, run RESTORE DATABASE [name] WITH RECOVERY to bring it online.

Do I need to fix users after a restore?

Often, when you restore to a different server. SQL logins are matched to database users by SID; if the logins were created separately, users become orphaned. Map them back with ALTER USER ... WITH LOGIN.

Restore from your browser instead

SQLBak Plus restores any backup it made to the same server — under a new database name or overwriting — from the web dashboard, with live progress. Free for one server.

Start free