Software Developer's Resources

Shopping Cart Systems
Mobile Text Marketing Solutions
Online Backup Solutions
ASP.NET Web Development
Skip Navigation Links.

How to Restore a Database

This article describes how to restore a Sql Server database from a backup.

Suppose we have a database containing information about the planets in our solar system: Planets.

We've backed up the database into a BAK file named Planets.bak.

Get Logical File Names

Display the logical file names:

RESTORE FILELISTONLY
FROM DISK = 'E:\Backups\Planets.bak'

Here's a portion of the result set:

LogicalName PhysicalName Type
Planets e:\MSSQL\Planets.mdf D
Planets_log e:\MSSQL\Planets.ldf L

Create Empty Database

Create an empty database and name it the same as the logical file name shown in the result set for the MDF.

  1. Select Databases in Microsoft Sql Server Management Studio
  2. Right-click and select New Database...
  3. Sql Studio displays the New Database dialog.
  4. Enter the database name into the "Database name" field.
  5. For our example, we enter "Planets" for the database name.
  6. Click OK.

Restore the database

Restore the database:

RESTORE DATABASE [Planets]
FROM DISK = 'E:\Backups\Planets.bak'
WITH REPLACE

Users & Logins

You may need to create users and logins that were not backed up in the backup set.

Test

Examine the restored database and check that it contains the tables, stored procedures, etc. you expect to find in the database.

Run an application that accesses the database and validate whether the database contains the expected data.