-
Written By Yousuf Hasan
-
Updated on January 7th, 2021
SQL Server Database is mainly used to store data on the server and keep a record of files and many corporate companies also use SQL server for maintaining attendance sheets and keeping salary records. But sometimes accidentally the user deletes files from the SQL Server which results in a huge loss. Therefore in this article, I will share some techniques through which you can easily restore deleted records in SQL Server and access them without any hassle.
I’ll share some manual techniques which might also work in getting back the deleted records and if by chance they fail then you have to spend some bucks and try professional recovery software. It is really difficult to recover deleted or lost records from the database but we can give a try by following the manual methods and see if the manual methods can fix this problem or not.
First try the manual procedure and if it fails, then move to the Professional method.
LSN means Log Sequence numbers which identify the time of SQL Log Transaction when it has occurs. So you can get back deleted data with the help of LSN. But the prerequisite for this method is that you should remember the time and date when you have deleted the data. You can follow the steps given below to get back erased data in SQL Database:-
SELECT * FROM Table_name
USE Databasename
GO
BACKUP LOG [Databasename]
TO DISK = N’D:\Databasename\RDDTrLog.trn’
WITH NOFORMAT, NOINIT,
NAME = N’Databasename-Transaction Log Backup’,
SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
USE Databasename
GO
Select [Current LSN] LSN], [Transaction ID], Operation, Context, AllocUnitName
FROM
fn_dblog(NULL, NULL)
WHERE Operation = ‘LOP_DELETE_ROWS’
Now, you’ll get the transaction of all the deleted record and if you have got the transaction I.D. of the lost record then go to the next step.
USE Databasename
GO
SELECT
[Current LSN], Operation, [Transaction ID], [Begin Time], [Transaction Name], [Transaction SID]
FROM
fn_dblog(NULL, NULL)
WHERE
[Transaction ID] = ‘Transaction of your deleted data′
AND
[Operation] = ‘LOP_BEGIN_XACT’
You’ll get the LSN value of your deleted record and now, it is the time to restore deleted records in SQL Server.
Recover Deleted D USE Databasename
GO
RESTORE DATABASE Databasename_COPY FROM
DISK = ‘D:\Databasename\RDDFull.bak’
WITH
MOVE ‘Databasename’ TO ‘D:\RecoverDB\Databasename.mdf’,
MOVE ‘Databasename_log’ TO ‘D:\RecoverDB\Databasename_log.ldf’,
REPLACE, NORECOVERY;
GO
USE Databasename
GO
RESTORE LOG Databasename_COPY FROM DISK=N’D:\Databasename\RDOTrLog.trn’ WITH STOPBEFOREMARK=‘lsn:0x00000020:000001d0:0002′
USE Databasename_Copy GO Select * from Table_name
You May Also Read- SQL Server Login Error 18456
I hope this manual method will help you out to resolve your issue but there are some drawbacks of using the manual methods.
The professional tool is the only solution for getting back the deleted data in SQL Database and it also defeats all the disadvantages of the manual methods and neither is it time taking nor there is any chance of data loss. The user can easily recover all the data either it is deleted or has gone corrupted.
The ball is in your court and you have to decide which method will be the best option for recovering records and if you are having good technical knowledge then you can try the manual method otherwise you should go with the Software because it is quick and there are no chances of data loss during the recovery process. So, make your choice and restore deleted records in SQL Server.
About The Author:
Related Post
© Copyrights 2013-2024 N. Sem’s Blog
Semnatik.com is an Affiliate Partner of Sysinfo Tools Software Pvt. Ltd.