开发者

Restore a SQL Express database from a file backup

开发者 https://www.devze.com 2023-03-15 01:23 出处:网络
I\'m using a S开发者_C百科QL Express database on my development machine. Unfortunately, I had to re-install the operating system and all the software on the machine. Now I need help to restoring the d

I'm using a S开发者_C百科QL Express database on my development machine. Unfortunately, I had to re-install the operating system and all the software on the machine. Now I need help to restoring the database that I was using before the re-installation. I have a backup of all files on the computer from before re-installing, but how do I find and restore the database from it?


You say you have a backup, but I'm not convinced that you do. Do you have any *.BAK files on your machine?

If not, you need to locate the data file (and preferably the log file as well). Depending on how you created the database originally, the files /should/ be in the form of <database name>[_data].mdf (data file) and <database name>[_log].ldf (log file).

Once you've found the files, you can use CREATE DATABASE ... FOR ATTACH and if the log file is damaged you can use the option FOR ATTACH_REBUILD_LOG instead.

A couple of notes:

(a) if you have a backup of the database, the link Rick Liddle created will be useful. Depending on whether your new instance of SQLExpress is located in the same location, you may need to use WITH MOVE to move the data and/or log file to valid folders in order to restore your databases.

(b) depending on what happened to your old machine (e.g. did it crash and die, how was the backup obtained, etc.), the mdf and/or ldf files may not be restorable. This is what proper database backups are designed to insure against.

Are you sure you have an actual backup (.BAK)?


Create a new database. Right click Select Tasks Restore Files and FileGroups... Select File

0

精彩评论

暂无评论...
验证码 换一张
取 消