Is there any way to undelete a SQL server database and stored procedures? Is there any way to undelete a SQL server database and stored procedures? database database

Is there any way to undelete a SQL server database and stored procedures?


Restore from backup.

You do have a backup, right?

Edit:I'm assuming you probably did a right-click, "Delete" from SQL Management Studio? If so, that actually does a "drop" of the database, which literally removes the files from the hard drive. If this is the case, you'll have to restore from your latest backup (if you have one).

If you just did a "detach", then the MDF and LDF files are still on the hard drive, and you can simply attach them.


How exactly have you deleted it.

If you haven't made any changes to you disks file system since then (and not defraged) then its possible the file will still be sitting on the disk as windows doesn't delete the file completely, just the File Handle.

Have a look at something like this and you may be able to recover the .mdf/.ldf files from your HD.

http://www.undelete.com/file-recovery.aspx

If not, you'll have to restore from your last back.

And if you don't have a backup... you're screwed.


If you accidently deleted the database in SQL Server Management Studio by right clicking and hitting delete in a hurry and you have no backup then there might still be a chance of getting back the database:

  1. Don't do any save / delete file operations on the disk where the database file was stored, browsing should be ok.

  2. Find the location where the .mdf file used to be. In my case it was "c:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS2012\MSSQL\DATA". If you have multiple databases you can right click on an existing one, select properties and files. Find the location entry in the listbox under path (select and ctrl+c to copy it)

  3. Download a portable undelete program e.g. Recuva to a USB drive/stick (unzip) and run it from the USB drive/stick.

  4. Set the copied path as the "search location" in your undelete program (ctrl+v), recover "YOURDATABASE.mdf" and "YOURDATABASE_log.ldf" to the USB drive.

  5. Copy the files from USB drive/stick to the original location.

  6. In SQL Server Management Studio right click on "Databases" select "Attach.." click Add, select "YOURDATABASE.mdf".

  7. Get some coffee and think about backups :-)