简体   繁体   中英

How can I restore my SQL Server database in MSSMS?

I backed up my database, but chose to save it to a location of my own on my C drive, rather than the default location. From there I also copied it to a USB stick. So I have the old data. But how can I restore it?

I accidentally deleted a LOT of records that I need back. I see no "Undo" option in MSSMS, nor a "Rollback" option.

That was my first thought (to try to Undo or Rollback). So then I went to do a "Restore" but it failed.

Here is what I have tried:

在此处输入图片说明

I tried with the default settings which appeared, but after I clicked the OK button I got:

在此处输入图片说明

I thought this was probably because I didn't backup to the default location, but to my hard drive. So I tried getting to the backup file on my C drive by selecting the "Device" radio button and then the ellipsis dots button here:

在此处输入图片说明

...and then selected the file from the folder where I put it:

在此处输入图片说明

...but I still got "Restore Failed"

My next attempt (and the last thing I know to try) was to go to the usb stick (drive D).

So I clicked the ellipsis dot button again, removed the previous entry (C Drive) and added the D/usb stick, and selected the same file:

在此处输入图片说明

I selected OK there, and then OK again here:

在此处输入图片说明

...but the third time's a curse, so to speak: again, I got "Restore of Database failed"

在此处输入图片说明

I also tried restoring, not the database, but the files:

在此处输入图片说明

...but got this:

在此处输入图片说明

It must be possible to restore my database - after all, I do have two copies of it backed up. But how?

Because you were looking at it in SSMS, the database was considered in use.

You have two options.

  • In the 'options' table when doing the restore (on the left hand side), ensure you tick the 'close existing connections' box. (Note you will probably need to tick something about overwrite the existing database too.)
  • Restore to a new database (eg, FixToFams4_RESTORE_20201015) rather than overwriting the old, then transfer data you need from the restored database back to your original.

The latter is MUCH safer and my preferred option unless you are happy doing a complete rollback to the time it was when you took the backup.

If you are using the first option, I strongly suggest taking a backup of the current database before doing a restore to the old version, in case you've done some work (eg, created procedures etc) that you want back.

Another thing that can be done (moot for me now, as the issue has already been resolved), and which came from the MS SQL Server forum, is to run this command:

RESTORE DATABASE db FROM DISK = 'C:\Path\YourBackup.bak'

There is also this link the SQL Server experts provided.

...and other suggestions from them here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM