Question

I've got a bak file (which is a backup database file for a SQL server express 2005 mdf file) and I should obtain the MDF file so that I can work on its tables, how can I get the original MDF file from this bak file? I'm using Visual Studio 2012, is it necessary to have management studio? I've tried to restore this bak file to an empty database in another system containing Sql server express management studio 2008, but it says databases don't match, what is going wrong?

Was it helpful?

Solution 2

If you have created a blank database, to overwrite this with the backup you will need to specify the WITH REPLACE parameter.

Also, you may have to specify the MOVE parameter to put the files into the correct locations.

You should be able to quite easily find these options in the GUI when doing the restore, or alternatively you can script it out by using the reference here:

How to: Restore a Database to a New Location and Name (Transact-SQL)

OTHER TIPS

Keep in mind that restoring a database backup file will not give the original MDF (and LDF) files. The only way to get the original MDF file is to copy it You can execute the T-SQL suggested by steoleary in Visual Studio, see more here: How to: Run SQL Scripts in Solution Explorer. You can also do that in SQL Server management Studio.

The blank database you created doesn't help much, unless you want to synchronize the backup to it. But for that you would need a 3rd party tool

First, execute the following to find out the logical file names in your backup. This example is for the backup named TestFull.bak stored in E:\Test

RESTORE FILELISTONLY
FROM DISK = 'E:\Test\TestFull.bak'
GO

enter image description here

The logical names should be used in the next script. Also, update the paths and names used

RESTORE DATABASE YourDB
FROM DISK = 'E:\Test\TestFull.bak'
WITH MOVE 'test1' TO 'E:\test\TestMDFFile.mdf',
MOVE 'test1_log' TO 'E:\test\TestLDFFile.ldf'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top