Recover deleted data from SQL Server - sql-server

How can I retrieve deleted data from a table in an SQL Server Database with full recovery model?

To Recover the deleted SQL Data first repair the error that caused the error.
Open DB Browse for your Database
Click on Execute SQL tab
In the console type the command 'PRAGMA integrity_Check' and click on the Play button
Once it is known the Database is in a consistent state run the command DBCC DBREPAIR to run repair DB files
Rebuild the database with REPAIR_REBUILD option
Now you can easily recover the files in SQL Database.
Recover deleted database in SQL and get your files back.

Related

Database restore is missing tables

I am using SSMS 2017 and attempting to restore a SQL Server 2016 backup (.bak) file to a new database (the data file and log file names in the original backup are different from the new database I am restoring to), so for example, db1.bak is being used to create a new database called db2 through a restore operation.
After the restore completes, all stored procedures and views are present, but none of the tables are there.
These are the steps I've taken in SSMS to perform the restore:
Right click the Databases folder
Select "Restore Database"
Under the General Page: For "Source" I choose Device and select the db1.bak file, and for "Destination" I enter the name of the new database to be created from the backup (db2)
Under the Files Page I select Relocate all files to folder (both Data and Log folder paths have been pre-populated with the correct names) as have the Logical File Name and the Restore As paths.
Under the Options Page I either select nothing or select Overwrite the existing database (WITH REPLACE).
Once the restore completes "successfully" I expand the newly created db2 and click to expand the tables and receive this error message:
What am I doing wrong?
Here is the script:
USE [master]
RESTORE DATABASE [PdsClone] FROM DISK = N'F:\SQLBackups\PDS_backup_2017_12_12_001015_0199267.bak' WITH FILE = 1, MOVE N'PDS_Data' TO N'E:\Program Files\Microsoft SQL Server\MSSQL13.PDS\MSSQL\DATA\PdsClone.mdf', MOVE N'PDS_Log' TO N'E:\Program Files\Microsoft SQL Server\MSSQL13.PDS\MSSQL\DATA\PdsClone_log.ldf', NOUNLOAD, REPLACE, STATS = 5 GO
UPDATE
I had the server group add another disk to that server and moved the SQL backups there, and I was able to successfully complete the restore this morning. I had previously cleaned off most of the backup files, but could it have been a space issue that prevented the tables from showing up in the restore? Every try it indicated success but no tables. They are there now, and I am thankful for your suggestions and help!
Not really an answer to what happened, but perhaps SSMS was doing something a little buggy as #JeroenMostert suggested.

SQL Server: How to attach / repair a detached / damaged database?

A database server crashed. I was able to get the mdf and the log file and I am trying to mount it on another server. I don't have backup as it was a development database.
When I try to attach the mdf and ldf files, Sql Server Management Studio give me this error:
TITLE: Microsoft SQL Server Management Studio
------------------------------
Attach database failed for Server
------------------------------
Could not redo log record (457:14202:19), for transaction ID (0:478674), on page (1:519205), database 'WSS_Content_5555' (database ID 15). Page: LSN = (370:463:113), type = 1. Log: OpCode = 2, context 2, PrevPageLSN: (298:40524:64).
Restore from a backup of the database, or repair the database.
During redoing of a logged operation in database 'WSS_Content_5555', an error occurred at log record ID (457:14202:19).
Typically, the specific failure is previously logged as an error in the Windows Event Log service.
Restore the database from a full backup, or repair the database.
Could not open new database 'WSS_Content_5555'.
CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 3456)
I don't know how to repair the database. Does it need to be attached before beeing repaired? In that case, how can I attach it?
You can try a workaround. In short:
Create a dummy DB with the same name (may need to remove the real DB first, save the original files or rename then).
Take the dummy off line (detach and (set offline or stop the SQL service)).
Delete dummy files, replace then with the real DB files.
Try to re-attach de DB
Edit
As by OP comment note you also can need to rebuild the log (if you lost transactions)
ALTER DATABASE [MyDatabase ] REBUILD LOG ON (NAME=’MyDatabaseLog’,FILENAME=’D:\Microsoft SQL Server\YourDataPath\Data\Logfile.ldf’)
and put the DB in multiple users log (taking the DB off can require you to put it in single use mode)
ALTER DATABASE [nomdb] SET MULTI_USER
For all the gore details you can refer to the Paul Randal Article
(Note in this article the author uses EMERGENCY MODE to (attempt) repair the transaction log)
I already used it with success but depending on the extent of the damage or others details it can be a impossible task. Consider restoring a backup.
Note this stunts are fine in a development server but you really need to plan (and drill) for disaster recovery in a prodution server.

restore .bak mssql 2005 to a new a server of mssql 2008r2

I created a .bak file (backup) from server A with the with following specs: Windows server 2003, MSSQL 2005. Now I would like to restore this backup on a new Server B with the following specs: Windows 8, MSSQL 2008 R2. I did the following to try and do the restore
Copy files to the new server(Server B)
Clicked on Microsoft SQL Server Management Studio 2008R2(Server B)
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
On the source for restore area, Clicked From device and located the .bak file, select it and cliked ok.
Instead of getting the success message, I get the following error:
Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended)
Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo).
Please assist, Im am new to MSSQL
Right click on Databases to create a new Database called Boom (Server B)
After creating the new Database(Boom), right clicked on Tasks->Restore->Database and
Well now you're making a new database and trying to overwrite it with a different database's backup. Hence:
The backup set holds a backup of a database other than the existing 'Boom' database
There's a WITH REPLACE option that allows you to proceed, but just avoid the indirection to begin with: restore the database, don't make a new one.
You'll probably need to delete the redundant Boom database you made, first. If, for whatever reason, you couldn't delete the database you'd have to use WITH REPLACE.
"Restore failed for Server 'Server B'.(Microsft.SqlServer.SmoExtended) Additional information: System.Data.SqlError: The backup set holds a backup of a database other than the existing 'Boom' database(Microsoft.SqlServer.Smo)."
I encountered this error when the logical name of the files do not match. Check on the logical name of the database you backed up and you will need the same logical name for the new database you created.
Or you can surely use the With Replace option too as specified by ta

How to delete database from SQL Server if .mdf and .ldf file is removed from the machine?

I have restore database into SQL Server as WMDATA.
One day my friend using my machine and removed .mdf and .ldf file for WMDATA.
Now I want to remove WMDATA database from my SQL Server but it gives me error for .mdf and .ldf file.
DROP DATABASE WMDATA should work, because it will drop a database even if it is suspect.
If that doesn't help, you should add some more useful information: what version of MSSQL; how are you dropping the database; what is the error message etc. You might also get a better answer on the DBA or Server Fault sites.
I run into this issue as well, while trying to delete some localdb databases through SSMS and DROP DATABASE didn't work for me. However, I found that it is possible to "recreate" the database after an unsuccessful deletion. I did the following:
Delete the database, get error that .mdf files are missing.
Create new database with the same name.
Delete the database again, this time without errors.
PS: If you don't do step 1, you get an error in step 2 that a database with that name already exists.
Right click on the DB > Delete
Uncheck "Delete backup and restore history information for databases"
Check "Close existing connections"
And hit OK.

restoring database

I had to uninstall SQL Server 2005, because it was configured to be used only in windows authentication mode, and install it again in mixed mode. I had to take a backup of my only database there, and restore it again on installing the sql server back, though the backup was taken successfully but when am trying to restore it, it is giving me an error as
System.Data.SqlClient.SqlError: The media has 2 media families but only 1 are provided. All members must be provided. (Microsoft.SqlServer.Smo)
I am using SQL server management studio, and trying to restore the database by right clicking on the databases folder, selecting restore database option, and then providing a database name, in "destination for restore", and in "source for restore" am selecting from device option and then providing with the path of my .bak file(backup file of the database), but the thing is not working, saying that the restored has failed and giving the above mentioned description for the error.
I suggest that you do not use the SSMS GUI to perform your database RESTORE unless you are familiar with all of the various options and settings. Using the T-SQL RESTORE command you can define explicitly what you are looking to do.
I would suggest that you first verify your database backup file by using the RESTORE VERIFYONLY command.
See SQL Server Books online:
http://msdn.microsoft.com/en-us/library/ms188902.aspx
Is there any chance you backed up to two backup files (ie, striped backup), and you're only specifying one of them in the restore? The restore seems to be complaining that if can't find all the files it needs to start the restore.
if you haven't already tried this: crate a blank database with the exact same name as the data base you're restoring from, with the files at the exact same location. right click the blank database and restore from your backup.

Resources