Let us pretend you have been sent a database backup file called mydatabase.bak.

Open a SQL Query Analyzer window.

First, verify that the backup file is not corrupted, by executing this command:

restore verifyonly from disk=C:\downloads\mydatabase.bak

Next, list the files that are inside this backup file (apparently, backup files are like zip files and contain other files).

restore filelistonly from disk=C:\downloads\mydatabase.bak

The above command produces a list like this:

mydevelopmentdatabase_Data	D:\Program Files\Microsoft SQL Server\MSSQL\data\mydatabase_data.MDF	D	PRIMARY 3080192	35184372080640	1	0	0 00000000-0000-0000-0000-000000000000	0	0	0	512	1	NULL 109000000080700003 F5793BAE-5730-46C8-9B5A-20BDA28D8746	0	1mydevelopmentdatabase_Log	D:\Program Files\Microsoft SQL Server\MSSQL\data\mydatabase_Log.LDF	L	NULL	30212096 35184372080640	2	0	0 00000000-0000-0000-0000-000000000000	0	0	0	512	0	NULL 0	00000000-0000-0000-0000-000000000000	0	0

On your system, you would restore (but overwrite! --- note the replace keyword) the database with the following command:

restore database mydatabase from    disk=C:\downloads\mydatabase.bak    with replace, recovery,    move mydevelopmentdatabase_Data     to D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\mydatabase_data.MDF,    move mydevelopmentdatabase_Log     to D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\mydatabase_Log.LDF

Notice in the command above, with the move clause, we can move the location of either file in the original backup to where those files would be more appropriately kept in our own system.

So, more generically, the command is:

restore database <name of database> from    disk=<where ever your backup file is>    with replace, recovery,    move <name of database>_Data     to <location you want to store DB file>\<name of your database>_Data.MDF,    move <name of database>_Log     to <location you want to store DB file>\<name of your database>mydatabase_Log.LDF