How to recover deleted rows from SQL server table? - sql-server-2005

I accidentaly ran a DELETE command against a table with a wrong WHERE
clause.
I am using SQL Server 2005.
Is there a way that could help me recover the lost data?

It is possible using Apex Recovery Tool,i have successfully recovered my table rows which i accidentally deleted
if you download the trial version it will recover only 10th row
check here http://www.apexsql.com/sql_tools_log.aspx

You have Full data + Transaction log backups, right? You can restore to another Database from backups and then sync the deleted rows back. Lots of work though...
(Have you looked at Redgate's SQL Log Rescue? Update: it's SQL Server 2000 only)
There is Log Explorer

I think thats impossible, sorry.
Thats why whenever running a delete or update you should always use BEGIN TRANSACTION, then COMMIT if successful or ROLLBACK if not.

What is gone is gone. The only protection I know of is regular backup.

Related

SQL restore data from transaction log

I have a transaction which update data today, but the code used in the transaction have bugs and some of the data updated wrongly.
May i ask if it's possible to restore data by using the transaction log stored in the database?
Thanks a lot
using a full back up and a collection of transaction logs you can restore a database to a point in time. If you are looking to not take the database offline to restore, you would need to restore the database to a new database and identify the data that you want to fix and manually "fix" it. See https://technet.microsoft.com/en-us/library/ms190982(v=sql.105).aspx
Its very complicated to restore from Tlog,unless you know what you are looking for..use some kind of tool like Apex SQL log (not a freeware) to generate statements from Tlog
You can read more details here
http://www.apexsql.com/sql_tools_log.aspx

How to get deleted data from table

I want to find deleted data from table in my SQL Server on a particular date like 17 JUNE 2012 (27/06/2012).
Is there any query which will provide this result?
If you have a backup from before the delete, then you will need to restore it.
There are some recovery tools out there using transaction logs, but they aren't cheap (there are some with trials) and I'm not sure if it works on logs from before installing the tool. It also may require that the delete happened in a transaction. If it didn't then the data is probably gone.
i.e.
http://www.apexsql.com/sql_tools_log.aspx
It's not helpful now, but the moral here is: Use transactions when deleting anything, and do backups regularly.

Is there any way to rollback transactions in SQL Server?

Yesterday I wrote some code module, that wrote wrong data in almost 400 existing records in important database on SQL Server 2008. I didn't make backup of this database (my mistake). So the question is how do I rollback these 400 transactions? Is there any way to do this? Thanks.
You can't rollback, but if the database is in full recovery model, then you can restore to another servar with stopat, and recover the deleted rows from there.
You can roll back a transaction as long as you haven't committed it.
But if you ran it yesterday, chances are very high you did commit - and then there's no way back.
So you're options are to
either restore a backup (and next time remember to take one before such an operation!)
manually "undo" those 400 transactions

roll back SQL query executed by mistake

I think the question says it all,
the following update query has been executed - by mistake - in SQL Server management studio
update kms_students set student_campus='4' where student_campus='KL'
The effected rows are more than 1000, and i can't identify it since that table is already have the student_campus='4' for many previous rows.
Is it possible to roll back?
I believe ApexSQL should do the trick.
ApexSQL works by analyzing the physical transaction log which basically has all the necessary info to restore specific transactions and data, but MS doesn't provide an out-of-box tool to manage it, other than restoring a backup and then manually restoring the transaction log up to a particular date using RESTORE LOGS
Backup. Most Hosting companies keep one, try calling everyone asap.
Your own backups. Even if they're old they will be helpful.
Keep lots of Backups and NEVER try out queries on production environment. NEVER.(Bet you learned that, right?)
To make it a bit easier, you can try putting the backup DB online and execute some PHP/Python/whatever so as to compare each record from the Backup and change the current database fom '4' to 'KL' where needed.
May not be perfect, but can help you avoid a few days of work.

How to recover a deleted row from SQL Server 2005 table?

How to recover a deleted row from SQL Server 2005 table?
If you have database backups that have deleted data:
Restore backup in separate database and recover deleted data from there
If there are no backups but your database is in full recovery mode:
Try reading transaction log using some third party transaction log
reader or using DBCC LOG command.
You’ll need help from third party tools because transaction log is not well documented. This is because it’s purpose is not to be used for this kind of recovery. However, if you can read it there are a lot of useful details there that can be used to recover accidentally deleted data.
Rollback the transaction (if you started one).
Restore a backup (if you have one).
[edit] If you have transaction logs, you should be able to restore the backup of the database to the point roughly just before the row was deleted (assuming you know when that was).
There are two ways we can recovery specific table:
The first one: restore fullback up with no recovery after restore with no_truncate option for t-log backup
The second way: using triggers we can recovery deleted tables with audit table.
The ApexSQL Log tool can be the solution for deleted rows. In case the DELETE operation exists (the database was not using the Simple recovery model) in database transaction logs (online, backups), the tool can create an undo T-SQL script for the operation.
Disclaimer: I work as a Product Support Engineer at ApexSQL
Don't forget to set full recovery model for a database if you need the "restore to a point in time" option!